2024-05-10 09:05:20 +00:00
|
|
|
SELECT *, 100 * dwindle / total `percentage`
|
2021-04-06 11:46:38 +00:00
|
|
|
FROM (
|
2024-05-10 09:05:20 +00:00
|
|
|
SELECT u.name buyer,
|
2024-09-16 10:32:52 +00:00
|
|
|
SUM(w.saleTotal) total,
|
|
|
|
SUM(
|
|
|
|
w.saleExternalWaste +
|
|
|
|
w.saleFaultWaste +
|
|
|
|
w.saleContainerWaste +
|
|
|
|
w.saleBreakWaste +
|
|
|
|
w.saleOtherWaste
|
|
|
|
) dwindle
|
2021-04-06 11:46:38 +00:00
|
|
|
FROM bs.waste w
|
2024-05-10 09:05:20 +00:00
|
|
|
JOIN account.user u ON u.id = w.buyerFk
|
|
|
|
JOIN vn.itemType it ON it.id = w.itemTypeFk
|
|
|
|
WHERE w.year = YEAR(util.VN_CURDATE() - INTERVAL 1 WEEK)
|
|
|
|
AND w.week = WEEK(util.VN_CURDATE() - INTERVAL 1 WEEK, 4)
|
|
|
|
GROUP BY buyerFk
|
2021-04-06 11:46:38 +00:00
|
|
|
) sub
|
2024-05-10 09:05:20 +00:00
|
|
|
ORDER BY `percentage` DESC;
|