MySQL-Basics-Exercises -Database Programmability - Exercise 9. People with Balance Higher Than
По условие на задачата трябва да сортираме по first_name, last_name и account id, но всъчщност judge иска да е само по id... това след хиляди теста минава със 100 т.
CREATE PROCEDURE usp_get_holders_with_balance_higher_than(amount DECIMAL (19,4))
BEGIN
SELECT first_name, last_name FROM
(SELECT a.id, first_name, last_name, sum(a.balance) AS total FROM account_holders AS ah
JOIN accounts a
ON a.account_holder_id=ah.id
GROUP BY ah.first_name,ah.last_name)
AS tb
WHERE tb.total>amount
ORDER BY tb.id;
END;