|
>What I'm trying to do is use the count function in a >case statement like I'm using the sum function below: > >Select fielda, fieldb, > sum(case when "MONTH" = 1 then sales else 0 end) > sum(case when "MONTH" = 2 then sales else 0 end) > . >From Filez >Group by fielda, fieldb When I try it, SQL insists that MONTH be in my group by clause: select name, case when zip='55555' then count(*) end, case when zip='54321' then count(*) end from master group by name Column ZIP or expression specified in SELECT list not valid. (this works if I put ZIP in the group by) Peter's suggestion works, but may not make logical sense because of the group by: select name, sum(case when zip='55555' then 1 end), sum(case when zip='54321' then 1 end) from master group by name These yield identical results for me. Buck
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.