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 2008 Forums
 Other SQL Server 2008 Topics
 Tricky sql select problem

Author  Topic 

sqlnewbie77
Starting Member

2 Posts

Posted - 2011-05-28 : 13:36:28
Need to write a SQL query that finds the most popular season from example table:

ID | RespondentName | FavoriteSeason
1 | John | Summer
2 | Jane | Summer
3 | Mark | Fall
4 | Paul | Winter
5 | Jeff | Spring

Needs to calculate the "favorite" and return JUST the name of the season

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-05-28 : 13:53:51
select top 1 FavouriteSeason, count(*)
from tbl
group by FavouriteSeason
order by count(*) desc

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sqlnewbie77
Starting Member

2 Posts

Posted - 2011-05-28 : 14:03:04
Thanks!! worked great!!
Go to Top of Page
   

- Advertisement -