Count wrong on SQL statement -
01-26-2007
, 12:25 PM
I have a sql query that does not provide the correct counts.
select location.name as "location Name",
count ( case when incident.location_type = 138 AND
incident_detail.witnessed = TRUE then 1 else null end) as "Fall
witnessed"
from incident, incident_detail, location
where location.id = incident.id
The is only 1 incident in my test DB that has a
incident_detail.witnessed set to true, so the outut should be
location name | Fall Witnessed
==================================
Floor | 0
Room | 0
Hallway | 1
But I get instead ;
location name | Fall Witnessed
==================================
Floor | 1
Room | 1
Hallway | 1
What am I doing wrong here?
Is it becasue the query is from mutlitple tables?
Let me know i you can help
Thanks |