当前位置:网站首页>SQL question brushing and sorting in leetcode of partial deduction
SQL question brushing and sorting in leetcode of partial deduction
2022-06-11 01:20:00 【CYC has a lot of hair】
1873. Calculate special bonuses
select employee_id,
case
when employee_id in (select employee_id from Employees where name not like "M%" and employee_id%2=1) then salary
else 0
end as bonus
from Employees
order by employee_id;practice case when...then... when...then... else... end Judgment statement , The results are stored in end In the field immediately following .
196. Delete duplicate email
DELETE p1 from Person p1 join Person p2 on p1.email=p2.email and p1.id>p2.id;The title requires the use of delete sentence , You can use first select do .
Input
Person surface :
+---+-------+
| id | email |
+---+-------+
| 1 | A |
| 2 | B |
| 3 | A |
+---+-------+
Through the first select View all results
select * from Person p1 join Person p2 on p1.email=p2.email;The result is :( The fields from left to right are :p1.id,p1.email,p2.id,p2.email)
1 A 1 A
3 A 1 A
2 B 2 B
1 A 3 A
3 A 3 A
According to the title , Try to delete 3 A that will do ,
if delete p1( Just look at the first two fields ) Add criteria to filter out 3 A 1 A perhaps 3 A 3 A,
if delete p2( Just look at the last two fields ) Add criteria to filter out 1 A 3 A perhaps 3 A 3 A,
If you want to filter out 3 A 3 A, Only use p1.id=p2.id, here 1 A 1 A and 2 B 2 B Will also be screened out , It doesn't fit the question ,
therefore about delete p1 Only use p1.id>p2.id, about delete p1 Only use p1.id<p2.id.
1484. Sell products by date
select
sell_date,
count(distinct product) num_sold,
group_concat(distinct product order by product asc separator ',') products
from
Activities
group by
sell_date;group_concat: Connect the data in the group
distinct: By default, they are arranged in ascending field order , To change the sort by order by modify
order by product asc separator ',':distinct Default ascending order ,group_concat Default ‘,’ Connect , So this paragraph sql It can be omitted
边栏推荐
- 中国专利奖政策支持介绍,补贴100万
- [introduction to ROS] - 03 ROS workspace and function pack
- 中国专利奖奖金多少,补贴100万
- Beijing Pinggu District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
- ion_mmap
- 立个flag--重构promise
- Beijing Dongcheng District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
- Promise
- Beijing Tongzhou District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
- WPF basic controls
猜你喜欢

【ROS入门教程】---- 03 ROS基本概念及指令

云呐|PDA无线固定资产盘点管理系统

Why is the digital transformation of small and medium-sized enterprises so difficult?

Team management | how to improve the thinking skills of technical leaders?

IRS application release 16: H5 application design guide
![[introduction to ROS] - 01 introduction to ROS](/img/6f/67ebb4336b6f7b3a1076b09d871b8e.png)
[introduction to ROS] - 01 introduction to ROS

Solution to prompt "network initialization failed operation failed" in PD virtual machine installation system

最好的创意鼓工具:Groove Agent 5

About log traffic monitoring and early warning small project | database management tool: migrate

Recruitment | Nanjing | triostudio Sanli Agency - Interior Designer / construction drawing deepening Designer / device / Product Designer / Intern, etc
随机推荐
The file "setup" does not exist. What should I do?
Introduction to the subsidy fund for leading technological innovation of Beijing enterprises, with a subsidy of 5million yuan
WSL 自动更新 ip hosts 文件
Pd虚拟机安装系统提示 “网络初始化失败 操作失败 ”的解决方案
ion_dma_buf_begin_cpu_access
Beijing Dongcheng District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
Inventory management and strategy mode
IRS application release 16: H5 application design guide
A/B机器正常连接后, B机器突然重启, 问A此时处于TCP的 什么状态?如何消除服务器程序中的这个状态?
Teach you the front and back separation architecture (V) system authentication implementation
87. (leaflet house) leaflet military plotting - straight arrow modification
明朝的那些皇帝
Blend for visual studio overview
Non presented paper (no show) policy
ava.lang.NoClassDefFoundError: org/apache/velocity/context/Context解决办法
ion_ dma_ buf_ begin_ cpu_ access
What are the advantages of increased life insurance products? Is the threshold high?
SSH远程登陆配置sshd_config文件详解
Current limiting and download interface request number control
Summary of pytorch classification problems