sql - simplify multiple group clauses -
ok, have following query:
select p.[page_id] , count(*) count ( select p.[page_id] , o.country_id [pages] p join page_item_position pip on p.page_id = pip.page_id join items on pip.item_id=i.item_id group tp.page_id, i.country_id) p group p.page_id
so, pages have items, items have countries , items exist @ particular position on page (this not related issue though). nothing complicated here.
what i'm trying find out, how many different countries represented on each pages, query above does. however, can't think little on complicated.
the inner query groups such direct listing of specific countries against pages, , outer part groups result id again give me count.
can query simplified?
try this:
select p.[page_id], count(distinct i.country_id) [pages] p inner join page_item_position pip on p.page_id = pip.page_id inner join items on pip.item_id=i.item_id group p.page_id
Comments
Post a Comment