目录
题目
纽约大学和加州大学之间举行了一场比赛。这场比赛由两所大学中相同数量的学生参加。拥有更多优秀学生的大学赢得这场比赛。如果两所大学的优秀学生数量相同,则这场比赛平局。
优秀学生是指在考试中获得 90%
或更高成绩的学生。
返回:
- "New York University" 若纽约大学赢得这场比赛。
- "California University" 若加州大学赢得这场比赛。
- "No Winner" 若这场比赛平局。
准备数据
Create table If Not Exists NewYork (student_id int, score int)
Create table If Not Exists California (student_id int, score int)
Truncate table NewYork
insert into NewYork (student_id, score) values ('1', '90')
insert into NewYork (student_id, score) values ('2', '87')
Truncate table California
insert into California (student_id, score) values ('2', '89')
insert into California (student_id, score) values ('3', '88')
newyork表
california表
分析数据
with t1 as (
select count(student_id) c1 from newyork
where score >= 90
),t2 as (
select count(student_id) c2 from california
where score >= 90
)select
case
when c1 > c2 then 'New York University'
when c1 < c2 then 'California University'
when c1 = c2 then 'No Winner'
end winner
from t2,t1;
总结
判断多类型,可是使用case when