M
mary cox
Table: characters
charID int
name string
playerID int
Table: sightings
charID int
time timestamp
I listed the parts of my db that seem necessary to construct the queries
I'm trying to figure out. There are actually 3 of them:
1. generate a comparison of two specific characters, showing the number
of times that they have been sighted at the same time. I think I have this
one, but please let me know if this is a poor way to do it:
select count(*) from sightings s1, sightings s2
where (s1.charID = (select charID from characters where name = 'bob')) and
(s2.charID = (select charID from characters where name = 'jane'))
and (s1.time = s2.time)
2. generate a list of all characters that have NEVER been seen at the same
time as a specific character. The list should show the character names and
the total number of times each has ever been sighted, ordered by that count
of sightings (descending).
example:
bob is the specified character.
jane has never been seen at the same time as bob.
jane has been seen a total of 18 times.
jack has never been seen at the same time as bob.
jack has been seen a total of 7 times.
sue has been seen at least once at the same time as bob.
sue has been seen a total of 5 times.
output:
jane 18
jack 7
3. the same as number 2 except it's a list of all characters that have
never
been sighted at the same time as a specified character AND none of the other
characters with the same playerID have been seen at the same time as the
specified character either.
example:
same as number 2 except sue and jack have the same playerID
output:
jane 18
I'm running these queries on an access db so far, but may end up porting
to msde or mysql. So I'm hoping there's a generic way to write these
that'll
work on other engines.
Thanks in advance,
John Cox
charID int
name string
playerID int
Table: sightings
charID int
time timestamp
I listed the parts of my db that seem necessary to construct the queries
I'm trying to figure out. There are actually 3 of them:
1. generate a comparison of two specific characters, showing the number
of times that they have been sighted at the same time. I think I have this
one, but please let me know if this is a poor way to do it:
select count(*) from sightings s1, sightings s2
where (s1.charID = (select charID from characters where name = 'bob')) and
(s2.charID = (select charID from characters where name = 'jane'))
and (s1.time = s2.time)
2. generate a list of all characters that have NEVER been seen at the same
time as a specific character. The list should show the character names and
the total number of times each has ever been sighted, ordered by that count
of sightings (descending).
example:
bob is the specified character.
jane has never been seen at the same time as bob.
jane has been seen a total of 18 times.
jack has never been seen at the same time as bob.
jack has been seen a total of 7 times.
sue has been seen at least once at the same time as bob.
sue has been seen a total of 5 times.
output:
jane 18
jack 7
3. the same as number 2 except it's a list of all characters that have
never
been sighted at the same time as a specified character AND none of the other
characters with the same playerID have been seen at the same time as the
specified character either.
example:
same as number 2 except sue and jack have the same playerID
output:
jane 18
I'm running these queries on an access db so far, but may end up porting
to msde or mysql. So I'm hoping there's a generic way to write these
that'll
work on other engines.
Thanks in advance,
John Cox