Reputation:
I have to create a TOP 10 of gross revenue/country/month with the statement :
dimensions:
metric: gross_revenue (only top 10 products type per country/month)
I have tried a big query program below between 2 tables :
SELECT FORMAT_DATE("%Y-%m",t0.order_create_date) AS month, t0.site_country AS country, p0.product_type AS product, SUM(t0.item_sale_price) AS gross_revenue
FROM transactions
t0
LEFT JOIN products
p0
ON t0.item_id = p0.item_id
where rn <= 10
ORDER BY
month ASC
LIMIT
I also tried this:
Upvotes: 0
Views: 74
Reputation: 428
select *
from(
select *, ROW_NUMBER() OVER (PARTITION BY country ORDER BY gross_revenue DESC) AS rn
from(
SELECT FORMAT_DATE("%Y-%m",t0.order_create_date) AS month,
t0.site_country AS country,
p0.product_type AS product,
SUM(t0.item_sale_price) AD gross_revenue
FROM transactions t0
LEFT JOIN products p0 ON t0.item_id = p0.item_id)x )xx
where rn <= 10
Upvotes: 0