题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1) WITH t AS((SELECT caller_id call_id, duration FROM Calls) UNION ALL (SELECT callee_id, duration FROM Calls)), t1 AS(SELECT id, c.name FROM Person JOIN Country c ON country_code = SUBSTRING(phone_number, 1, 3)) SELECT name country FROM t JOIN t1 ON call_id = id GROUP BY name HAVING AVG(duration) > (SELECT AVG(duration) all_country_avg FROM t) -- 解决方案(2) SELECT c.name AS country FROM Calls, Person, Country c WHERE (caller_id = id OR callee_id = id) AND country_code = LEFT(phone_number, 3) GROUP BY country_code HAVING AVG(duration) > (SELECT AVG(duration) FROM Calls);