Ai
1 Star 0 Fork 0

逸扬/leetcode-hub-mysql

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
lc-0618.test 1.18 KB
一键复制 编辑 原始数据 按行查看 历史
逸扬 提交于 2022-04-29 01:18 +08:00 . 569-571-618-1225-1384-1454-2010 (7)
# $618. 学生地理信息报告
# https://leetcode-cn.com/problems/students-report-by-geography/
# SQL架构
Create table If Not Exists Student (name varchar(50), continent varchar(7));
Truncate table Student;
insert into Student (name, continent) values ('Jane', 'America');
insert into Student (name, continent) values ('Pascal', 'Europe');
insert into Student (name, continent) values ('Xi', 'Asia');
insert into Student (name, continent) values ('Jack', 'America');
# Write your MySQL query statement below
select
max(
case
continent
when 'America' then name
else null
end
) as America,
max(
case
continent
when 'Asia' then name
else null
end
) as Asia,
max(
case
continent
when 'Europe' then name
else null
end
) as Europe
from
(
select
name,
continent,
row_number() over (
partition by continent
order by
name
) as rk
from
Student
) tmp
group by
rk;
# clean-up
drop table Student;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gdut_yy/leetcode-hub-mysql.git
git@gitee.com:gdut_yy/leetcode-hub-mysql.git
gdut_yy
leetcode-hub-mysql
leetcode-hub-mysql
master

搜索帮助