BootyBean
02-17-2005, 08:38 PM
Hi. I'm trying to create a query but I'm not sure how to get what I'm looking for.
Here is a sample structure to what I'm using with just 2 tables. It is a database to record bird observations.
[observation] //one row per date surveyed; one to many relationship to [birdtally]
ID, site, Date
[birdtally] //row for each bird seen on this observation date
ID, bird, Total
I want to return a list of dates and 'total' for a specific site and specific bird so that I can chart that bird's numbers for each survey. So I used this query:
SELECT DISTINCT birdtally.Total, DATE_FORMAT(observation.Date,'%m/%d/%Y') as 'humandate'FROM birdtally LEFT JOIN observation ON observation.ID = birdtally.ID WHERE site='Lake Boogaloo' AND Bird='Bald Eagle' ORDER BY observation.Date
This returns close to what I want. The problem is that it only returns dates on which a Bald Eagle was seen. I need for it to return a row for every date surveyed, with a '0' for dates which no Bald Eagles were seen.
So if my sample database looked like this:
[observation]
1, Lake Boogaloo, 2000/1/1
2, Lake Boogaloo, 2000/1/2
3, Lake Boogaloo, 2000/1/3
[birdtally]
ID, bird, Total
1, American Coot, 4
1, Bald Eagle, 2
1, Common Raven, 3
2, Mallard, 4
2, Ruddy Duck, 3
3, Bald Eagle, 3
3, American Coot, 5
Then I want the result to be:
1/1/2000, 2
1/2/2000, 0
1/3/2000, 3
Here is a sample structure to what I'm using with just 2 tables. It is a database to record bird observations.
[observation] //one row per date surveyed; one to many relationship to [birdtally]
ID, site, Date
[birdtally] //row for each bird seen on this observation date
ID, bird, Total
I want to return a list of dates and 'total' for a specific site and specific bird so that I can chart that bird's numbers for each survey. So I used this query:
SELECT DISTINCT birdtally.Total, DATE_FORMAT(observation.Date,'%m/%d/%Y') as 'humandate'FROM birdtally LEFT JOIN observation ON observation.ID = birdtally.ID WHERE site='Lake Boogaloo' AND Bird='Bald Eagle' ORDER BY observation.Date
This returns close to what I want. The problem is that it only returns dates on which a Bald Eagle was seen. I need for it to return a row for every date surveyed, with a '0' for dates which no Bald Eagles were seen.
So if my sample database looked like this:
[observation]
1, Lake Boogaloo, 2000/1/1
2, Lake Boogaloo, 2000/1/2
3, Lake Boogaloo, 2000/1/3
[birdtally]
ID, bird, Total
1, American Coot, 4
1, Bald Eagle, 2
1, Common Raven, 3
2, Mallard, 4
2, Ruddy Duck, 3
3, Bald Eagle, 3
3, American Coot, 5
Then I want the result to be:
1/1/2000, 2
1/2/2000, 0
1/3/2000, 3