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
 loop data

Author  Topic 

pamyral_279
Posting Yak Master

143 Posts

Posted - 2010-05-05 : 02:11:02
Hi all,
I have structure table as :

QuestionID---Answer
1--------------10
2--------------50
3--------------10
4--------------90
5--------------90
6--------------90
.....
Expected output
Answer--Count
10------2
50------1
90------3
........
Anyone help me ?
Thank you very much.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-05-05 : 02:12:14
[code]
select Answer, count(*)
from yourtable
group by Answer
[/code]


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

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-05 : 02:14:02
select Answer,count(*) as [Count]
from table
group by Answer
order by Answer


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-05 : 02:14:43
This old rocker was too late again...



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

pamyral_279
Posting Yak Master

143 Posts

Posted - 2010-05-05 : 02:18:33
Thanks very much.I did it.
Go to Top of Page
   

- Advertisement -