2021-04-26 11:40:52 +00:00
|
|
|
DROP PROCEDURE IF EXISTS `bs`.`weekWaste`;
|
2021-04-06 11:46:38 +00:00
|
|
|
|
2021-04-26 11:40:52 +00:00
|
|
|
DELIMITER $$
|
|
|
|
$$
|
|
|
|
CREATE DEFINER = `root`@`%` PROCEDURE `bs`.`weekWaste__`()
|
2021-04-06 11:46:38 +00:00
|
|
|
BEGIN
|
2021-04-26 11:40:52 +00:00
|
|
|
DECLARE vWeek INT;
|
2021-04-06 11:46:38 +00:00
|
|
|
DECLARE vYear INT;
|
|
|
|
|
|
|
|
SELECT week, year
|
2021-04-26 11:40:52 +00:00
|
|
|
INTO vWeek, vYear
|
|
|
|
FROM vn.time
|
|
|
|
WHERE dated = DATE_ADD(CURDATE(), INTERVAL -1 WEEK);
|
2021-04-06 11:46:38 +00:00
|
|
|
|
2021-04-26 11:40:52 +00:00
|
|
|
SELECT *, 100 * dwindle / total AS percentage
|
|
|
|
FROM (
|
|
|
|
SELECT buyer,
|
|
|
|
SUM(saleTotal) AS total,
|
|
|
|
SUM(saleWaste) AS dwindle
|
|
|
|
FROM bs.waste
|
|
|
|
WHERE year = vYear
|
|
|
|
AND week = vWeek
|
|
|
|
GROUP BY buyer
|
|
|
|
) sub
|
|
|
|
ORDER BY percentage DESC;
|
|
|
|
END;$$
|
|
|
|
DELIMITER ;
|
2021-04-06 11:46:38 +00:00
|
|
|
|