题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
WITH t1 AS(SELECT user_id, credit FROM Users UNION ALL SELECT paid_by, -amount FROM Transactions UNION ALL SELECT paid_to, amount FROM Transactions) SELECT user_id, user_name, SUM(t1.credit) credit, IF(SUM(t1.credit) > 0, 'No', 'Yes') credit_limit_breached FROM t1 JOIN Users USING(user_id) GROUP BY user_id