Skip to content

Instantly share code, notes, and snippets.

@julie-mills
Created January 31, 2024 03:14
Show Gist options
  • Save julie-mills/150cbe7ed6c524c6eb6cc3afbd2b6027 to your computer and use it in GitHub Desktop.
Save julie-mills/150cbe7ed6c524c6eb6cc3afbd2b6027 to your computer and use it in GitHub Desktop.
INSERT INTO
mv_daily_sales_summary
SELECT
o.tenant_id AS seller_id,
p.product_category,
o.order_date AS sale_date,
COUNT(*) AS total_orders,
SUM(o.total_amount) AS total_sales
FROM
orders o
JOIN products p ON o.product_id = p.product_id
AND o.tenant_id = p.tenant_id
WHERE
o.order_date > CURRENT_DATETIME - TIMESTAMP_MILLIS(o._last_scheduled_completion_time)
GROUP BY
seller_id,
p.product_category,
sale_date
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment