sql server - SQL: Sub Query to filter the result of a Query -


select sum(imps.[count]) , count (imps.interest_name) b, ver.vertical_name impressions imps inner join verticals ver  on imps.campaign_id = ver.campaign_id ver.vertical_name = 'retail' or ver.vertical_name = 'travel' group imps.interest_name, ver.vertical_name; 

the above query returns record :

  b   vertical_name  6  6   retail  3  2   retail  7  1   travel 13  10  travel 

i want modify query result such :

  b   vertical_name  9  8   retail  20 11  travel 

that further grouping vertical name , taking sum of colums , b. guess has done sub query buy not sure how?

just group vertical_name , remove imps.interest_name group by since doing count (imps.interest_name) on it.

select sum(imps.[count]) , count (imps.interest_name) b, ver.vertical_name impressions imps inner join verticals ver  on imps.campaign_id = ver.campaign_id ver.vertical_name = 'retail' or ver.vertical_name = 'travel' group ver.vertical_name; 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -