Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
nachi
Starting Member
7 Posts |
Posted - 2005-08-17 : 14:12:32
|
| Could some one help me in the following queryI have a table with the following structureid Monyear type value -- ------- ---- -----1 jan2005 A Y2 jan2005 A Y3 jan2005 B N4 jan2005 B Y5 feb2005 A NI need a query with the following results for each month and for all types in that month, I need the count of Y and Count of N on the value field. Value field will not have values other than 'Y' or 'N'Result should beMonyear type count_Y count_Njan2005 A 2 0jan2005 B 1 1feb2005 A 0 1 |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-08-17 : 14:23:35
|
| [code]SELECT Monyear, type, SUM(CASE WHEN value = 'Y' THEN 1 ELSE 0 END) AS [count_Y], SUM(CASE WHEN value = 'N' THEN 1 ELSE 0 END) AS [count_N]FROM MyTableGROUP BY Monyear, type[/code]Kristen |
 |
|
|
nachi
Starting Member
7 Posts |
Posted - 2005-08-17 : 14:53:09
|
| Thanks for the reply. I also got it right. |
 |
|
|
|
|
|