当前位置:网站首页>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
边栏推荐
- ion_ dma_ buf_ begin_ cpu_ access
- 中国专利奖奖金多少,补贴100万
- [original] expdp parameter content
- Josephus problem_ Unidirectional circular linked list_ code implementation
- Redis data has been overwritten
- Beijing Pinggu District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
- Inventory management and strategy mode
- WPF - timeline class
- 北京企业前沿引领技术创新补助资金介绍,补助500万
- The best creative drum tool: groove agent 5
猜你喜欢

项目_基于网络爬虫的疫情数据可视化分析

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

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

Simple select sort and heap sort
![[introduction to ROS] - 01 introduction to ROS](/img/6f/67ebb4336b6f7b3a1076b09d871b8e.png)
[introduction to ROS] - 01 introduction to ROS

【VBA脚本】提取word文档中所有批注的信息和待解决状态

Viewpager and dot of bottom wireless loop

条码固定资产管理系统的作用,固定资产条码化管理

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

简述自定义注解
随机推荐
Norme de soutien à la culture des entreprises de haute technologie du district de Mentougou à Beijing, subvention de 100 000 RMB
ava.lang.NoClassDefFoundError: org/apache/velocity/context/Context解决办法
北京门头沟区高新技术企业培育支持标准,补贴10万
Traversal (pre order, middle order, post order) and search of binary tree
[paper reading] fixmatch: simplifying semi supervised learning with consistency and confidence
CentOS actual deployment redis
Summary of pytorch classification problems
[introduction to ROS] - 03 basic concepts and instructions of ROS
北京企业前沿引领技术创新补助资金介绍,补助500万
OTA升级
复利的保险理财产品怎么样?可以买吗?
中间件_Redis_05_Redis的持久化
限流与下载接口请求数控制
"Past and present" of permission management
CSRF攻击
Basic introduction of graph and depth first traversal and breadth first traversal
cosine 相似度计算总结
zabbix离线安装
北京門頭溝區高新技術企業培育支持標准,補貼10萬
Support standard for cultivation of high-tech enterprises in Miyun District, Beijing, with a subsidy of 100000 yuan