我试图总结预览30天的每个日期,但是,它并没有总结任何东西 在下面的SQL中,我尝试获取订单日期X所有订单来自If Date> = Date -30days then SUM(订单最近30天)END
SELECT
a.Shop_Country
,a.order_date
,a.Order_Week
,SUM(a.number_Orders) as orders
,CASE WHEN a.Order_Date >= DATE_ADD(b.Order_Date, -30, "day") THEN SUM(a.number_Orders) ELSE 0 END as total_orders
FROM
[marketing-int:finance_report.overall_view] a
JOIN [marketing-int:finance_report.overall_view] b
ON a.Order_Date = b.Order_Date
GROUP BY
a.Shop_Country
,a.Order_Date
,b.Order_Date
,a.Order_Week
,a.Order_Channel
,a.number_Orders
答案 0 :(得分:0)
尝试以下
SELECT
Shop_Country
,order_date
,Order_Week
,SUM(number_Orders) OVER(PARTITION BY Shop_Country ORDER BY Order_Date
RANGE BETWEEN 29 PRECEDING AND CURRENT ROW) AS total_orders
FROM
[marketing-int:finance_report.overall_view]
希望这对你来说是一个好的开始
有关详细信息,请参阅events
property的window-frame-clause
部分