168 lines
5.3 KiB
Python
168 lines
5.3 KiB
Python
from __future__ import annotations
|
|
|
|
AW_DAILY_SALES_QUERIES = [
|
|
"""
|
|
SELECT
|
|
CAST(d.FullDateAlternateKey AS date) AS sale_date,
|
|
SUM(f.SalesAmount) AS revenue,
|
|
SUM(f.TotalProductCost) AS cost,
|
|
SUM(f.OrderQuantity) AS quantity,
|
|
COUNT_BIG(*) AS orders
|
|
FROM dbo.FactInternetSales AS f
|
|
INNER JOIN dbo.DimDate AS d ON d.DateKey = f.OrderDateKey
|
|
GROUP BY CAST(d.FullDateAlternateKey AS date)
|
|
ORDER BY sale_date;
|
|
""",
|
|
"""
|
|
SELECT
|
|
CAST(OrderDate AS date) AS sale_date,
|
|
SUM(SalesAmount) AS revenue,
|
|
SUM(TotalProductCost) AS cost,
|
|
SUM(OrderQuantity) AS quantity,
|
|
COUNT_BIG(*) AS orders
|
|
FROM dbo.FactInternetSales
|
|
GROUP BY CAST(OrderDate AS date)
|
|
ORDER BY sale_date;
|
|
""",
|
|
]
|
|
|
|
WWI_DAILY_SALES_QUERIES = [
|
|
"""
|
|
SELECT
|
|
CAST(i.InvoiceDate AS date) AS sale_date,
|
|
SUM(il.ExtendedPrice) AS revenue,
|
|
SUM(il.TaxAmount) AS cost,
|
|
SUM(il.Quantity) AS quantity,
|
|
COUNT_BIG(DISTINCT i.InvoiceID) AS orders
|
|
FROM Sales.Invoices AS i
|
|
INNER JOIN Sales.InvoiceLines AS il ON il.InvoiceID = i.InvoiceID
|
|
GROUP BY CAST(i.InvoiceDate AS date)
|
|
ORDER BY sale_date;
|
|
""",
|
|
"""
|
|
SELECT
|
|
CAST(i.InvoiceDate AS date) AS sale_date,
|
|
SUM(il.UnitPrice * il.Quantity) AS revenue,
|
|
CAST(0 AS float) AS cost,
|
|
SUM(il.Quantity) AS quantity,
|
|
COUNT_BIG(DISTINCT i.InvoiceID) AS orders
|
|
FROM Sales.Invoices AS i
|
|
INNER JOIN Sales.InvoiceLines AS il ON il.InvoiceID = i.InvoiceID
|
|
GROUP BY CAST(i.InvoiceDate AS date)
|
|
ORDER BY sale_date;
|
|
""",
|
|
]
|
|
|
|
AW_PRODUCT_PERFORMANCE_QUERIES = [
|
|
"""
|
|
SELECT
|
|
p.ProductAlternateKey AS product_id,
|
|
p.EnglishProductName AS product_name,
|
|
COALESCE(sc.EnglishProductSubcategoryName, 'Unknown') AS category_name,
|
|
SUM(f.SalesAmount) AS revenue,
|
|
SUM(f.TotalProductCost) AS cost,
|
|
SUM(f.OrderQuantity) AS quantity,
|
|
COUNT_BIG(*) AS orders
|
|
FROM dbo.FactInternetSales AS f
|
|
INNER JOIN dbo.DimProduct AS p ON p.ProductKey = f.ProductKey
|
|
LEFT JOIN dbo.DimProductSubcategory AS sc ON sc.ProductSubcategoryKey = p.ProductSubcategoryKey
|
|
GROUP BY p.ProductAlternateKey, p.EnglishProductName, sc.EnglishProductSubcategoryName
|
|
ORDER BY revenue DESC;
|
|
""",
|
|
"""
|
|
SELECT
|
|
CAST(ProductKey AS nvarchar(100)) AS product_id,
|
|
CAST(ProductKey AS nvarchar(100)) AS product_name,
|
|
'Unknown' AS category_name,
|
|
SUM(SalesAmount) AS revenue,
|
|
SUM(TotalProductCost) AS cost,
|
|
SUM(OrderQuantity) AS quantity,
|
|
COUNT_BIG(*) AS orders
|
|
FROM dbo.FactInternetSales
|
|
GROUP BY ProductKey
|
|
ORDER BY revenue DESC;
|
|
""",
|
|
]
|
|
|
|
WWI_PRODUCT_PERFORMANCE_QUERIES = [
|
|
"""
|
|
SELECT
|
|
CAST(s.StockItemID AS nvarchar(100)) AS product_id,
|
|
s.StockItemName AS product_name,
|
|
COALESCE(cg.StockGroupName, 'Unknown') AS category_name,
|
|
SUM(il.ExtendedPrice) AS revenue,
|
|
SUM(il.TaxAmount) AS cost,
|
|
SUM(il.Quantity) AS quantity,
|
|
COUNT_BIG(*) AS orders
|
|
FROM Sales.InvoiceLines AS il
|
|
INNER JOIN Warehouse.StockItems AS s ON s.StockItemID = il.StockItemID
|
|
LEFT JOIN Warehouse.StockItemStockGroups AS sig ON sig.StockItemID = s.StockItemID
|
|
LEFT JOIN Warehouse.StockGroups AS cg ON cg.StockGroupID = sig.StockGroupID
|
|
GROUP BY s.StockItemID, s.StockItemName, cg.StockGroupName
|
|
ORDER BY revenue DESC;
|
|
""",
|
|
"""
|
|
SELECT
|
|
CAST(il.StockItemID AS nvarchar(100)) AS product_id,
|
|
CAST(il.StockItemID AS nvarchar(100)) AS product_name,
|
|
'Unknown' AS category_name,
|
|
SUM(il.UnitPrice * il.Quantity) AS revenue,
|
|
CAST(0 AS float) AS cost,
|
|
SUM(il.Quantity) AS quantity,
|
|
COUNT_BIG(*) AS orders
|
|
FROM Sales.InvoiceLines AS il
|
|
GROUP BY il.StockItemID
|
|
ORDER BY revenue DESC;
|
|
""",
|
|
]
|
|
|
|
AW_CUSTOMER_QUERIES = [
|
|
"""
|
|
SELECT
|
|
CAST(c.CustomerAlternateKey AS nvarchar(100)) AS customer_id,
|
|
c.FirstName + ' ' + c.LastName AS customer_name,
|
|
SUM(f.SalesAmount) AS revenue,
|
|
COUNT_BIG(*) AS orders
|
|
FROM dbo.FactInternetSales AS f
|
|
INNER JOIN dbo.DimCustomer AS c ON c.CustomerKey = f.CustomerKey
|
|
GROUP BY c.CustomerAlternateKey, c.FirstName, c.LastName
|
|
ORDER BY revenue DESC;
|
|
""",
|
|
"""
|
|
SELECT
|
|
CAST(CustomerKey AS nvarchar(100)) AS customer_id,
|
|
CAST(CustomerKey AS nvarchar(100)) AS customer_name,
|
|
SUM(SalesAmount) AS revenue,
|
|
COUNT_BIG(*) AS orders
|
|
FROM dbo.FactInternetSales
|
|
GROUP BY CustomerKey
|
|
ORDER BY revenue DESC;
|
|
""",
|
|
]
|
|
|
|
WWI_CUSTOMER_QUERIES = [
|
|
"""
|
|
SELECT
|
|
CAST(c.CustomerID AS nvarchar(100)) AS customer_id,
|
|
c.CustomerName AS customer_name,
|
|
SUM(il.ExtendedPrice) AS revenue,
|
|
COUNT_BIG(DISTINCT i.InvoiceID) AS orders
|
|
FROM Sales.Invoices AS i
|
|
INNER JOIN Sales.InvoiceLines AS il ON il.InvoiceID = i.InvoiceID
|
|
INNER JOIN Sales.Customers AS c ON c.CustomerID = i.CustomerID
|
|
GROUP BY c.CustomerID, c.CustomerName
|
|
ORDER BY revenue DESC;
|
|
""",
|
|
"""
|
|
SELECT
|
|
CAST(i.CustomerID AS nvarchar(100)) AS customer_id,
|
|
CAST(i.CustomerID AS nvarchar(100)) AS customer_name,
|
|
SUM(il.UnitPrice * il.Quantity) AS revenue,
|
|
COUNT_BIG(DISTINCT i.InvoiceID) AS orders
|
|
FROM Sales.Invoices AS i
|
|
INNER JOIN Sales.InvoiceLines AS il ON il.InvoiceID = i.InvoiceID
|
|
GROUP BY i.CustomerID
|
|
ORDER BY revenue DESC;
|
|
""",
|
|
]
|