dbTalk Databases Forums  

Count wrong on SQL statement

comp.databases.postgresql comp.databases.postgresql


Discuss Count wrong on SQL statement in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bigjim
 
Posts: n/a

Default 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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.