Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Query not Returning

Status
Not open for further replies.

petperson

Programmer
Oct 2, 2002
106
US
I'm trying to get a count of households where there is not a Head of household defined. There are different account types for different members of a household - but there should only be one head of household. Please help!

My query is set up like:

SELECT HH,
COUNT(HH) NumOccur
FROM HHOLDS
where account_type = 'HEAD'
GROUP BY HH
HAVING ( COUNT(HH) = 0 )
 
Code:
SELECT hh
     , SUM(CASE WHEN account_type = 'HEAD'
                THEN 1 ELSE 0 END ) AS NumOccur 
  FROM hholds
GROUP 
    BY hh
HAVING NumOccur = 0

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top