其他分享
首页 > 其他分享> > 每日一题-88(大满贯数量)

每日一题-88(大满贯数量)

作者:互联网

题88:

根据下面两个表请写出查询语句,查询出每一个球员赢得大满贯比赛的次数,结果不包含没有赢得比赛的球员的ID 。
在这里插入图片描述
其中:

解题思路:
(1)先用union all行转列
(2)连接(1)和Players表
(3)根据player_id进行分组
(4)查询想要的字段

select player_id ,player_name ,count(grand_slams) grand_slams_count
from (
    select Wimbledon grand_slams
    from Championships 

    union all

    select Fr_open grand_slams
    from Championships 

    union all

    select US_open grand_slams
    from Championships  

    union all  

    select Au_open grand_slams
    from Championships 
) t 
left join Players p on t.grand_slams = p.player_id 
group by player_id ;

标签:大满贯,player,88,slams,grand,一题,Championships,id,select
来源: https://blog.csdn.net/Txixi/article/details/122748172