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
 NEED SQL QUERY TO SOLVE THE PROB

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]
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-06-10 : 08:05:16
Turn off your caps lock key, it's very annoying.
Go to Top of Page

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
Go to Top of Page

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 Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -