今日刷题
- 超过五名学生的课程
- 有趣的电影
- 交换性别
1、超过五名学生的课程
解题思路:
- 分组之后,直接用having筛选即可
- count()统计条数时,需要对学生名称去重,同一个人选同一课程多次不应计第二次人数
SQL语句:
select class
from courses
group by class
having count(distinct student) >= 5
2、有趣的电影
解题思路:
- where条件筛选即可
SQL语句:
select *
from cinema
where description <> 'boring' and id%2=1
order by rating desc
3、交换性别
解题思路:
- 此题需要用if(‘条件’,‘表达式1’,‘表达式2’) 三元表达式
SQL语句:
update salary set sex = if(sex='f','m','f')