当前位置:网站首页>[leetcode] [SQL] notes
[leetcode] [SQL] notes
2022-06-30 23:11:00 【myaijarvis】
code Format specification : All keywords are capitalized , Align keywords to the right , Clause indent
The column name should be the same as the column name in the table ( Case case )
SELECT name
FROM customer C
WHERE C.id NOT IN ( SELECT C1.id
FROM customer C1
WHERE C1.referee_id = 2 );
Reference material :
Official documents :【 Reference resources :MySQL :: MySQL 5.7 Reference manual :: 13 SQL sentence 】
【 Reference resources :MySQL Chinese document | MySQL Chinese net 】
【 Reference resources :SQL The predicate in - You know 】
Topics are categorized by type , Record common and error prone types
IS NULL
【 Reference resources :584. Looking for user references 【 Finer than official , A thousand words of dry goods !】( Ternary operation ,NULL) - Looking for user references - Power button (LeetCode)】
【 Reference resources :584. Looking for user references - Simple - Power button (LeetCode)】
SELECT name FROM customer WHERE referee_id != 2 OR referee_id IS NULL;
Multi-table query
【 Reference resources :183. Customers who never order - Power button (LeetCode)】
- Subquery
select customers.name as 'Customers' # as Alias
from customers
where customers.id not in
(
select customerid from orders
);
# First from orders To find out in the customerid
- Link query
【 Reference resources : The illustration SQL Interview questions : Find data that is not in the table - Customers who never order - Power button (LeetCode)】

SELECT c.Name as Customers
FROM Customers as c
left join Orders as o on c.Id=o.CustomerId
where o.Id IS NULL
IF expression
IF( expr1 , expr2 , expr3 )
【 Reference resources :1873. Calculate special bonuses - Power button (LeetCode)】
【 Reference resources :MySQL, 7 A solution - Calculate special bonuses - Power button (LeetCode)】
SELECT
employee_id,
IF(
employee_id%2=1 and name not like 'M%',
salary,
0
) as bonus
FROM Employees
ORDER by employee_id
【 Reference resources :627. Changing gender - Power button (LeetCode)】
UPDATE Salary set sex=IF(sex='f','m','f')
CASE WHEN END
【 Reference resources :627. Changing gender - Power button (LeetCode)】
UPDATE salary
SET
sex = CASE sex
WHEN 'm' THEN 'f'
ELSE 'm'
END
Self join
【 Reference resources :196. Delete duplicate email - Power button (LeetCode)】
【 Reference resources : Yes 「 official 」 In the solution “delete” and “>” The explanation of , recommend ! - Delete duplicate email - Power button (LeetCode)】
2、p1.Id > p2.Id
Before continuing , First, let's take a brief look at the connection process of the table , I understand this , understand WHERE The conditions are simple
a. From the drive table ( The left table ) Take out N Bar record ;
b. Take this. N Bar record , In turn, go to the driven table ( Right table ) Find satisfaction WHERE Record of conditions ;
DELETE p1
FROM Person p1,
Person p2
WHERE
p1.Email = p2.Email AND p1.Id > p2.Id
Regular
【 Reference resources :1527. A patient with a disease - Power button (LeetCode)】
^DIAB1 Said to DIAB1 start
| Express or
. Indicates that there must be any character
* It means repetition 0 To an infinite number of previous characters
first \ Indicates the escape character
\s It's blank , Including Spaces 、 Line break 、Tab Indent, all the blanks
therefore .*\sDIAB1 Express DIAB1 There is a space before and 0 To an infinite number of arbitrary characters
# Write your MySQL query statement below
select patient_id,
patient_name,
conditions
from Patients
where conditions rlike '^DIAB1|.*\\sDIAB1'
function
upper lower
【 Reference resources :1667. Fix the name in the table - Power button (LeetCode)】
【 Reference resources :【JMao】 Simple function solution + Share the experience of problem brushing - Fix the name in the table - Power button (LeetCode)】
【 Reference resources :12.3. String function _MySQL Chinese document 】
# Write your MySQL query statement below
SELECT user_id,
CONCAT(Upper(Left(name,1)),Lower(substring(name,2))) as name
from Users
order by user_id
concat
【 Reference resources :1484. Sell products by date - Power button (LeetCode)】
【 Reference resources :mysql Group splicing function group_concat - Sell products by date - Power button (LeetCode)】
SELECT sell_date,
count(distinct product) as 'num_sold',
# Intra group splicing
group_concat(distinct product # duplicate removal
order by product asc # grouping , In ascending order according to the dictionary
separator ',') # interval
as 'products'
from Activities
group by sell_date
order by sell_date
边栏推荐
- MIT博士论文 | 优化理论与机器学习实践
- CNN经典网络模型详解-LeNet-5(pytorch实现)
- Yolo target detection
- The sandbox is being deployed on the polygon network
- Schéma de transition asynchrone - générateur
- 股票开户要如何办理呢?办理手机开户安全吗
- Meet the StreamNative | 杨子棵:是什么让我放弃了大厂 Offer
- Sm2246en+ SanDisk 15131
- Shell multitasking to download video at the same time
- [golang] golang实现截取字符串函数SubStr
猜你喜欢

Redis的缓存穿透、缓存击穿和缓存雪崩

Online customer service system code_ H5 customer service_ Docking with official account_ Support app_ Support for multiple languages

As the public cloud market enters the deep water, can the calm Amazon cloud still sit still?

Introduction to machine learning compilation course learning notes lesson 2 tensor program abstraction

shell 同时执行多任务下载视频

Ideal interface automation project

在线客服系统代码_h5客服_对接公众号_支持APP_支持多语言

在线客服聊天系统源码_美观强大golang内核开发_二进制运行傻瓜式安装_附搭建教程...

conv2d详解--在数组和图像中的使用

Cas classique multithreadé
随机推荐
Qlineedit of QT notes (74) specifies the input type
零样本和少样本学习
Redis - 01 缓存:如何利用读缓存提高系统性能?
35 giant technology companies jointly form the meta universe standard Forum Organization
AtCoder Beginner Contest 255
未来十年世界数字化与机器智能展望
d编译时计数
基金客户服务
CesiumJS 2022^ 源码解读[6] - 三维模型(ModelExperimental)新架构
Code de conduite pour la vente de fonds et la gestion de l'information
35家巨头科技公司联合组成元宇宙标准论坛组织
Shell multitasking to download video at the same time
Deployment of microservices based on kubernetes platform
How to open a stock account? Is it safe to open a mobile account
Youfu network hybrid cloud accelerates enterprise digital transformation and upgrading
Prospects of world digitalization and machine intelligence in the next decade
MaxPool2d详解--在数组和图像中的应用
[无线通信基础-13]:图解移动通信技术与应用发展-1-概述
pytorch 的Conv2d的详细解释
The superficial understanding of the industrial Internet finally brought the development of the industrial Internet into the strange circle of the consumer Internet