题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
WITH t AS(SELECT *, SUM(salary) OVER(PARTITION BY experience ORDER BY salary) sumn FROM Candidates), tt AS(SELECT *, ROW_NUMBER() OVER(PARTITION BY experience ORDER BY sumn) rk FROM t), # 解决(Senior, Junior) = (MAX, MAX) & Senior <> 0 & Junior <> 0 ttt AS(SELECT IF(t1.experience = 'Senior', t1.rk, t2.rk) Senior, IF(t2.experience = 'Junior', t2.rk, t1.rk) Junior FROM tt t1 JOIN tt t2 ON t1.experience <> t2.experience AND t1.sumn + t2.sumn <= 70000 ORDER BY 1 DESC, 2 DESC LIMIT 1), # 解决(Senior, Junior) = (0, MAX) tttt AS(SELECT MAX(rk) junior_max_rk FROM tt WHERE experience = 'Junior' AND sumn <= 70000), # 解决(Senior, Junior) = (MAX, 0) ttttt AS(SELECT MAX(rk) senior_max_rk FROM tt WHERE experience = 'Senior' AND sumn <= 70000) SELECT 'Senior' experience, IF((SELECT COUNT(*) FROM ttt) = 0, 0, (SELECT * FROM ttttt)) accepted_candidates UNION ALL SELECT 'Junior', IF((SELECT COUNT(*) FROM ttt) = 0, (SELECT * FROM tttt), IF((SELECT * FROM ttttt) > (SELECT Senior FROM ttt), 0, (SELECT Junior FROM ttt)))