feat(statistics): implement top alert stocks, top last sales, top supplier debts, and top selling products endpoints with SQL queries
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
SELECT p.id
|
||||
FROM Products p
|
||||
WHERE (
|
||||
SELECT COALESCE(SUM(sb.quantity), 0)
|
||||
FROM Stock_Balance sb
|
||||
WHERE
|
||||
sb.productId = p.id
|
||||
) < p.minimumStockAlertLevel
|
||||
ORDER BY (
|
||||
p.minimumStockAlertLevel - (
|
||||
SELECT COALESCE(SUM(sb.quantity), 0)
|
||||
FROM Stock_Balance sb
|
||||
WHERE
|
||||
sb.productId = p.id
|
||||
)
|
||||
) DESC
|
||||
LIMIT 10
|
||||
Reference in New Issue
Block a user