在刷LeetCode的时候遇到的SQL题目
627.Swap Salary
Given a table salary
, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice versa) with a single update query and no intermediate temp table.
For example:
| id | name | sex | salary |
|----|------|-----|--------|
| 1 | A | m | 2500 |
| 2 | B | f | 1500 |
| 3 | C | m | 5500 |
| 4 | D | f | 500 |
After running your query, the above salary table should have the following rows:
| id | name | sex | salary |
|----|------|-----|--------|
| 1 | A | f | 2500 |
| 2 | B | m | 1500 |
| 3 | C | f | 5500 |
| 4 | D | m | 500 |
大概就是要求交换表中sex列的性别
一开始想着用update salary set sex = f when sex = m再用个AND,后来一想这样执行的结果应该是错的、
然后就偷看了solution,才知道还有when case语句,所以记录一下
update salary set sex =
case sex
when 'm' then 'f'
else 'm'
end;
大概意思就是when m,then就设置为f,else都设置为m
最新评论
有快3个月了没续费了,如何重新激活我的服务?
楼主,有一点不明白: “准备好你的服务器,确认账号(一般是 root)和密码,系统建议 Centos7 ×64+、Ubuntu、Debian”是指自己要准备一台安装了上述系统的电脑做服务器还是指购买的
网上一堆的节点怎么填写,看不懂得
请问证书会过期嘛?要怎么处理
好怕被墙,vmess+ws
搞定了!网速很快哦,感谢感谢!不过最后一步还是要提醒小白们一下,v2ray设置好以后,要点下电脑右下角的V,点击鼠标右键,点”系统代理”,点“自动配置系统代理”,V变成红色了,就可以google了。