LeetCode(数据库)- 学生地理信息报告

简介: LeetCode(数据库)- 学生地理信息报告

题目链接:点击打开链接

题目大意:略。

解题思路:原题此解决方案是需要一个前提——美洲学生最多,否则第 7 个用例通不过,如图所示,但题目没说,有点坑;进阶题是即使没有说明哪个洲学生最多也可以解(列转行思想)。

image.pngAC 代码

--原题WITHt1AS(SELECT*, ROW_NUMBER() OVER(ORDERBYname) rnkFROMstudentWHEREcontinent='America'),
t2AS(SELECT*, ROW_NUMBER() OVER(ORDERBYname) rnkFROMstudentWHEREcontinent='Asia'),
t3AS(SELECT*, ROW_NUMBER() OVER(ORDERBYname) rnkFROMstudentWHEREcontinent='Europe')
SELECTt1.nameAmerica, t2.nameAsia, t3.nameEuropeFROMt1LEFTJOINt2ONt1.rnk=t2.rnkLEFTJOINt3ONt1.rnk=t3.rnk--进阶selectmax(casewhencontinent='America'thennameelsenullend) asAmerica    ,max(casewhencontinent='Asia'thennameelsenullend) asAsia    ,max(casewhencontinent='Europe'thennameelsenullend) asEuropefrom (SELECT*, row_number() over(partitionbycontinentorderbyname) asrnfromstudent) tgroupbyrn
目录
相关文章
|
数据库
LeetCode(数据库)- 产品销售分析I
LeetCode(数据库)- 产品销售分析I
74 0
|
数据库
LeetCode(数据库)- 产品销售分析 III
LeetCode(数据库)- 产品销售分析 III
76 0
|
数据库
LeetCode(数据库)- 市场分析 I
LeetCode(数据库)- 市场分析 I
136 0
|
数据库
LeetCode(数据库)- 联赛信息统计
LeetCode(数据库)- 联赛信息统计
87 0
|
数据库
LeetCode(数据库)- 不同国家的天气类型
LeetCode(数据库)- 不同国家的天气类型
75 0
|
数据库
LeetCode(数据库)- 销售分析 II
LeetCode(数据库)- 销售分析 II
76 0
|
数据库
LeetCode(数据库)- 销售分析 III
LeetCode(数据库)- 销售分析 III
90 0
|
数据库
LeetCode(数据库)- 销售分析 I
LeetCode(数据库)- 销售分析 I
71 0
|
数据库
LeetCode(数据库)- 大的国家
LeetCode(数据库)- 大的国家
96 0
|
数据库
LeetCode(数据库)- 报告的记录
LeetCode(数据库)- 报告的记录
69 0