Skip to content

Instantly share code, notes, and snippets.

View anibihakeem's full-sized avatar

Hakeem Anibi anibihakeem

View GitHub Profile
@anibihakeem
anibihakeem / sum_of_order_quantity
Last active November 9, 2023 12:52
Rolling Sum of Order Quantity by Product
SELECT
ProductID,
SalesDate,
OrderQty,
SUM(OrderQty) OVER (
ORDER BY SalesDate
ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING
) AS RollingSumOrderQty
FROM sales_data
ORDER BY ProductID, SalesDate;
@anibihakeem
anibihakeem / partition_by_month
Created November 6, 2023 12:21
partition_by_month
SELECT
FORMAT(SalesDate,'MMM') AS Month,
Amount,
AVG(Amount)OVER(PARTITION BY DATEPART(Month,SalesDate)) AS Avg_amount_per_transaction
FROM sales_data