Этап: Аналитические запросы
This commit is contained in:
1 parent
d90f1f30b2
commit
2ec0b38d95
10 files changed
+315
-1
No files matched your search
@@ -0,0 +1,16 @@
|
||||
WITH RECURSIVE calendar(day, last_day) AS (
|
||||
SELECT MIN(order_date), MAX(order_date) FROM daily_category_revenue
|
||||
HAVING COUNT(*) > 0
|
||||
UNION ALL
|
||||
SELECT date(day, '+1 day'), last_day FROM calendar WHERE day < last_day
|
||||
),
|
||||
daily AS (
|
||||
SELECT day AS order_date, COALESCE(SUM(r.revenue_kopecks), 0) AS revenue_kopecks
|
||||
FROM calendar
|
||||
LEFT JOIN daily_category_revenue AS r ON r.order_date = day
|
||||
GROUP BY day
|
||||
)
|
||||
SELECT order_date, revenue_kopecks,
|
||||
revenue_kopecks - LAG(revenue_kopecks) OVER (ORDER BY order_date) AS change_kopecks
|
||||
FROM daily
|
||||
ORDER BY order_date;
|
||||
Reference in new issue
Block a user