简体   繁体   中英

Top N products type in every month - BIGQUERY

I have to create a TOP 10 of gross revenue/country/month with the statement:

dimensions:

  • date (month)
  • site_country
  • product type

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:

enter image description here

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
  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM