LeetCode(数据库)- 可以放心投资的国家

简介: LeetCode(数据库)- 可以放心投资的国家

题目链接:点击打开链接

题目大意:略。

解题思路:略。

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);
目录
相关文章
|
7月前
|
SQL
leetcode-SQL-1501. 可以放心投资的国家
leetcode-SQL-1501. 可以放心投资的国家
48 0
|
数据库
数据库LeetCode每日练习(三)
数据库LeetCode每日练习(三)
数据库LeetCode每日练习(三)
|
SQL 数据库
数据库LeetCode每日练习(二)
数据库LeetCode每日练习(二)
数据库LeetCode每日练习(二)
|
SQL 数据库
数据库LeetCode每日练习(一)
数据库LeetCode每日练习(一)
数据库LeetCode每日练习(一)
|
数据库
LeetCode(数据库)- Hopper Company Queries II
LeetCode(数据库)- Hopper Company Queries II
97 0
LeetCode(数据库)- Hopper Company Queries II
|
数据库
LeetCode(数据库)- 2142. The Number of Passengers in Each Bus I
LeetCode(数据库)- 2142. The Number of Passengers in Each Bus I
202 0
|
数据库
LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company II
LeetCode(数据库)- The Number of Seniors and Juniors to Join the Company II
117 0
|
数据库
LeetCode(数据库)- Number of Accounts That Did Not Stream
LeetCode(数据库)- Number of Accounts That Did Not Stream
116 0
|
数据库
LeetCode(数据库)- The Airport With the Most Traffic
LeetCode(数据库)- The Airport With the Most Traffic
130 0
|
数据库
LeetCode(数据库)- The Category of Each Member in the Store
LeetCode(数据库)- The Category of Each Member in the Store
118 0