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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combingin two 'where' statements

Status
Not open for further replies.

tommot82

Programmer
Aug 27, 2005
11
GB
Is there any neat way i can combine the following two statements to return me a single table of results with the columns:
lt2, lt3, id

select count(*) lt2,id
FROM TABLE
where Value<2
GROUP BY id

select count(*) lt3,id
FROM TABLE
where Value<3
GROUP BY id

Thanks for your help
tommot82
 
SELECT id,
SUM(CASE WHEN Value<2 THEN 1 ELSE 0 END) lt2,
SUM(CASE WHEN Value<3 THEN 1 ELSE 0 END) lt3
FROM TABLE
WHERE Value<3
GROUP BY id

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
nice one thankyou very much!! Much appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top