Showing posts with label group by two times in sql query. Show all posts
Showing posts with label group by two times in sql query. Show all posts

Tuesday, November 17, 2009

Group by and again group by and get results in sql query

Here,
there are two time , group by applied by using sub query in single query
Syntax of sql query:
following query showing with two time group by and data difference



select publisherWeb as Publisher,count(Adcount) as Adcount from

(
select publisherWeb,count(Adinfo) as Adcount from tblICA2008 where (DATEDIFF(Month, CAST(Year AS varchar) + '-' + CAST(Month AS varchar) + '-' + CAST(Day AS varchar), GETDATE()) <6) group by publisherWeb,Adinfo
) t

group by publisherWeb order by Adcount