Fix time out error on data import and fix regression on progress display + sort out core and metrics schemas better
This commit is contained in:
@@ -107,4 +107,24 @@ FROM
|
||||
LEFT JOIN
|
||||
product_metrics pm ON p.product_id = pm.product_id
|
||||
WHERE
|
||||
p.managing_stock = true;
|
||||
p.managing_stock = true;
|
||||
|
||||
-- Create view for sales trends analysis
|
||||
CREATE OR REPLACE VIEW product_sales_trends AS
|
||||
SELECT
|
||||
p.product_id,
|
||||
p.SKU,
|
||||
p.title,
|
||||
COALESCE(SUM(o.quantity), 0) as total_sold,
|
||||
COALESCE(AVG(o.quantity), 0) as avg_quantity_per_order,
|
||||
COALESCE(COUNT(DISTINCT o.order_number), 0) as number_of_orders,
|
||||
MIN(o.date) as first_sale_date,
|
||||
MAX(o.date) as last_sale_date
|
||||
FROM
|
||||
products p
|
||||
LEFT JOIN
|
||||
orders o ON p.product_id = o.product_id
|
||||
WHERE
|
||||
o.canceled = false
|
||||
GROUP BY
|
||||
p.product_id, p.SKU, p.title;
|
||||
Reference in New Issue
Block a user