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
 General SQL Server Forums
 New to SQL Server Programming
 want to get the count

Author  Topic 

divyaram
Posting Yak Master

180 Posts

Posted - 2011-12-08 : 02:48:24
Hi All,

I have table like this
----------------------------
Article| SP1| sp2|
--------------------------
art1 |1 |2
art2 |2 |3
art3 |1 |1
art4 |3 |2

i would like to get the count of all '1' in SP1 and SP2 together like that I have to get the count of all 2's and 3's

Required output like this

SP Count
--------------------
1 3
2 3
3 2

Thanks,
Divya

Regards,
Divya

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-08 : 03:25:11
[code]
select SP, count(*)
from
(
select SP1 as SP from table1
union all
select SP2 as SP from table1
) as d
group by SP[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -