题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
WITH t AS(SELECT member_id, COUNT(IFNULL(charged_amount, NULL)) * 100 / COUNT(*) score FROM Visits LEFT JOIN Purchases USING(visit_id) GROUP BY 1) SELECT m.member_id, m.name, CASE WHEN score IS NULL THEN 'Bronze' WHEN score >= 80 THEN 'Diamond' WHEN score >= 50 THEN 'Gold' ELSE 'Silver' END category FROM Members m LEFT JOIN t USING(member_id)