salix/print/templates/email/buyer-week-waste/sql/wasteWeekly.sql

11 lines
326 B
MySQL
Raw Normal View History

2021-04-06 11:46:38 +00:00
SELECT *, 100 * dwindle / total AS percentage
FROM (
SELECT buyer,
sum(saleTotal) as total,
sum(saleWaste) as dwindle
FROM bs.waste w
JOIN vn.time t ON w.year = t.year AND w.week = t.week
WHERE t.dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK)
GROUP BY buyer
) sub
ORDER BY percentage DESC;