LeetCode刷题记录
LeetCode刷题记录
此文章用于记录自己在LeetCode上遇到一些值得记录的题
数据库
因为最近工作需要自己写SQL,于是先就去找数据库类型的题来练习了:
- 178 分数排名
select a.Score as Score,(select count(distinct b.Score) from Scores b where b.Score>=a.Score) as 'Rank' from Scores a order by a.Score desc
- 596 超过五名学生的课-----多熟悉对group by 和 having 的理解和应用
select class from courses group by class having count(distinct student)>=5
- 627 交换性别
题目:请你编写一个 SQL 查询来交换所有的 ‘f’ 和 ‘m’ (即,将所有 ‘f’ 变为 ‘m’ ,反之亦然),仅使用 单个 update 语句 ,且不产生中间临时表。
注意,你必须仅使用一条 update 语句,且 不能 使用 select 语句。
update salary set sex = char(ascii('m') + ascii('f') - ascii(sex));
ascii(str) 回字符串 str 最左边的那个字符的 ASCII 码值
待更新
*纸上得来终觉浅,绝知此事要躬行。