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 |
ANGSHU
Starting Member
4 Posts |
Posted - 2011-06-09 : 22:47:50
|
I HAVE THE ABOVE TABLE......NOW I WANT TO FIND THE CUSTOMER ID WHO MAKES MAXIMUM COMMENTS AGAINST A PARTICULAR BLOGPOST ID |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-06-10 : 08:00:56
|
[code]DECLARE @YourBlogPostId INT; set @YourBlogPostId = 12345;WITH cte AS ( SELECT CustomerId, COUNT(*) N FROM AboveTable WHERE BlogPostId = @YourBlogPostId GROUP BY CustomerId)SELECT TOP 1 Customer Id FROM CTE ORDER BY N desc[/code] |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-06-10 : 08:05:16
|
Turn off your caps lock key, it's very annoying. |
|
|
ANGSHU
Starting Member
4 Posts |
Posted - 2011-06-11 : 23:02:35
|
quote: Originally posted by sunitabeck
DECLARE @YourBlogPostId INT; set @YourBlogPostId = 12345;WITH cte AS ( SELECT CustomerId, COUNT(*) N FROM AboveTable WHERE BlogPostId = @YourBlogPostId GROUP BY CustomerId)SELECT TOP 1 Customer Id FROM CTE ORDER BY N desc
THANKS [ sunitabeck ]...THANKS 4 HELPING ME |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-06-12 : 05:14:41
|
Please don't post in all caps. It's the online equivalent of shouting at people.--Gail ShawSQL Server MVP |
|
|
|
|
|