LeetCode(数据库)- 大满贯数量
Posted 程序员牧码
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode(数据库)- 大满贯数量相关的知识,希望对你有一定的参考价值。
题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1)
with a as (
select player_id, sum(
if(wimbledon=player_id,1,0)+
if(fr_open=player_id,1,0)+
if(us_open=player_id,1,0)+
if(au_open=player_id,1,0)) grand_slams_count
from championships
join (select player_id from players) b
group by player_id
)
select players.player_id,player_name, grand_slams_count
from players
left join a on players.player_id=a.player_id
having grand_slams_count>0
-- 解决方案(2)
WITH t AS(SELECT Wimbledon player_id, COUNT(*) cnt
FROM Championships c
GROUP BY Wimbledon
UNION ALL
SELECT Fr_open, COUNT(*) cnt
FROM Championships c
GROUP BY Fr_open
UNION ALL
SELECT US_open, COUNT(*) cnt
FROM Championships c
GROUP BY US_open
UNION ALL
SELECT Au_open, COUNT(*) cnt
FROM Championships c
GROUP BY Au_open)
SELECT player_id, player_name, SUM(cnt) grand_slams_count
FROM t JOIN Players USING(player_id)
GROUP BY player_id
以上是关于LeetCode(数据库)- 大满贯数量的主要内容,如果未能解决你的问题,请参考以下文章
什么是在 C++ 中获取总内核数量的跨平台代码片段? [复制]