|
|
|
|
|
by xivzgrev
1421 days ago
|
|
Can anyone explain why the query without having needs 14 separate queries? That seemed insane to me. It seems like the author is using one query per country. Where it seems like you’d just group by country and year, where country <> US You would need some unions to bolt on the additional aggregations, but it’s more like 4 queues, not 14 Eg select c.ctry_name, i.year_nbr,
sum(i.item_cnt) as tot_cnt,
sum(i.invoice_amt) as tot_amt
from country c
inner join invoice i on (i.ctry_code = c.ctry_code)
where c.ctry_name <> 'USA'
group by c.ctry_name, i.year_nbr |
|
Yeah, four queries for the four requirements seems the most straightforward, and easier to maintain than the final version.
But still a very nice illustrating of group by cube.