您好,欢迎来到年旅网。
搜索
您的当前位置:首页LeetCode SQL刷题笔记DAY2

LeetCode SQL刷题笔记DAY2

来源:年旅网

1. 题1873

if(employee_id % 2 = 1,(if(name like 'M%',0,salary)),0) AS bonus

name like 'M%' 可用 left(name,1)

2. 题627

update salary set sex = if(sex = 'm','f','m')

3. 题196

delete from Person 
where Id not in (
    select * from(
        select min(Id)
        from Person
        group by Email) t)
输入: 
Person 表:
+----+------------------+
| id | email            |
+----+------------------+
| 1  | john@example.com |
| 2  | bob@example.com  |
| 3  | john@example.com |
+----+------------------+
输出: 
+----+------------------+
| id | email            |
+----+------------------+
| 1  | john@example.com |
| 2  | bob@example.com  |
+----+------------------+
解释: john@example.com重复两次。我们保留最小的Id = 1

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务