我需要按月得出品牌的总销售额,例如10月份。我的数据在3个表中(带有键),calendar_sales_dim,sales_fact和product_dim。我已经设法拉出所有表格并将它们设置为别名,并且可以正常工作,但是我在哪里分组以及在何处/如何制作每月汇总销售额的窗口函数时遇到了麻烦。错误,错误,错误。
tables = response.xpath('//*[@id="openDataStatic"]//table')
for table in tables:
for row in table.xpath('./tr'):
local_authority = row.xpath('td[1]//text()').extract()
期望的结果:(给定的月份)
SELECT a.sales_year,
a.sales_monthofyear,
a.sales_day_key,
a.product_key,
a.order_amount,
a.brand_label,
a.total_money_earned
FROM
(SELECT a.sales_year,
a.sales_monthofyear,
a.sales_day_key,
a.product_key,
a.order_amount,
a.brand_label
FROM
(SELECT sales_year,
sales_monthofyear,
sf.sales_day_key,
sf.product_key,
order_amount,
brand_label
FROM calendar_sales_dim
JOIN sales_fact sf ON calendar_sales_dim.sales_day_key = sf.sales_day_key
JOIN product_dim pd ON sf.product_key = pd.product_key) AS a)AS a
等