Monday, March 12, 2012

Help needed on "conditional" COUNT

Hi,
I have to SELECT 2 COUNTS from a table which are conditional

i.e. one is COUNT rows where field1 = 0 and field2=0

and second is COUNT all rows

Is it possible in 1 SELECT statement to return such a resultset or what are the alternatives ?

Any input in this will sincerely be appreciated.

Thanks

If you want the values to appear in the same row, then you could use the example below.

Chris

SELECT SUM(CASE WHEN field1 = 0 AND field2 = 0 THEN 1 ELSE 0 END),

COUNT(*)

FROM MyTable

|||wow, How simple was it.

Thankyou,
I really appreciate it

No comments:

Post a Comment