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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 counting rows

Author  Topic 

e106199
Starting Member

13 Posts

Posted - 2006-01-23 : 21:44:13
Hi all,
how can i get the below table from the above one?
my table:
col1 col2
---- --------
abc 1/1/2006
abd 2/1/2006
abc 3/1/2006
abb 3/2/2006
abc 3/3/2006

from above table i want to get the below:
month countof ABC countof abd
----- ----------- -----------
jan 06 1 0
feb 06 0 1
mar 06 2 0

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-23 : 21:58:16
[code]select convert(varchar(6), col2, 112) as mth_yr,
sum(case when col1 = 'abc' then 1 else 0 end) as [count of abc],
sum(case when col1 = 'abb' then 1 else 0 end) as [count of abb]
from mytable
group by convert(varchar(6), col2, 112)
order by mth_yr[/code]

----------------------------------
'KH'

I do work from home but I don't do homework
Go to Top of Page

e106199
Starting Member

13 Posts

Posted - 2006-01-23 : 22:56:47
that was great
thank you
-shane
Go to Top of Page
   

- Advertisement -