当前位置:网站首页>[leetcode] [SQL] notes
[leetcode] [SQL] notes
2022-07-03 19:00:00 【Game programming】
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 nameFROM customer CWHERE 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 customerswhere 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 CustomersFROM Customers as cleft join Orders as o on c.Id=o.CustomerIdwhere o.Id IS NULLIF 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 EmployeesORDER 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 salarySET sex = CASE sex WHEN 'm' THEN 'f' ELSE 'm' ENDSelf 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 p2WHERE p1.Email = p2.Email AND p1.Id > p2.IdRegular
【 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 belowselect patient_id, patient_name, conditionsfrom Patientswhere 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 belowSELECT user_id, CONCAT(Upper(Left(name,1)),Lower(substring(name,2))) as name from Users order by user_idconcat
【 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 Activitiesgroup by sell_dateorder by sell_dateunion all
union and union all Can play the role of associating result sets , The difference lies in :
- union It will automatically remove the duplicate data in the associated two result sets ,
union all Will not actively remove duplicate data in the two result sets , All the data will be displayed ;
Column turned
【 Reference resources :1795. The price of each product in different stores - Power button (LeetCode)】
【 Reference resources : form - Column turned - The price of each product in different stores - Power button (LeetCode)】
# Write your MySQL query statement belowselect product_id, 'store1' as store, store1 as pricefrom Products where store1 is not nullunion allselect product_id, 'store2' as store, store2 as pricefrom Products where store2 is not nullunion allselect product_id, 'store3' as store, store3 as pricefrom Products where store3 is not null;author :myaijarvis
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .
边栏推荐
- flask 生成swagger文档
- FBI警告:有人利用AI换脸冒充他人身份进行远程面试
- Transformer T5 model read slowly
- Real time split network (continuous update)
- Help change the socket position of PCB part
- How to design a high concurrency system
- CV in transformer learning notes (continuously updated)
- 變化是永恒的主題
- Understanding of database architecture
- SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
猜你喜欢

Raft log replication

22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc

Dart JSON编码器和解码器剖析

SQL: special update operation

FBI警告:有人利用AI换脸冒充他人身份进行远程面试

application

We have built an intelligent retail settlement platform

Torch learning notes (3) -- univariate linear regression model (self training)
![[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time](/img/06/5a37e2dca9711f8322b657581c3d75.png)
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
![[Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University](/img/52/b97c618a8f2eb29ad0ccca221bb5c1.jpg)
[Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
随机推荐
ActiveMQ的基础
cipher
leetcode:556. Next larger element III [simulation + change as little as possible]
【Proteus仿真】用24C04与1602LCD设计的简易加密电子密码锁
Does SQL always report foreign key errors when creating tables?
math_泰勒公式
How to quickly view the inheritance methods of existing models in torchvision?
235. Ancêtre public le plus proche de l'arbre de recherche binaire [modèle LCA + même chemin de recherche]
The online customer service system developed by PHP is fully open source without encryption, and supports wechat customer service docking
Flutter network and data storage framework construction-b1
知其然,而知其所以然,JS 对象创建与继承【汇总梳理】
041. (2.10) talk about manpower outsourcing
What is the function of registering DLLs- What does registering a DLL do?
Flask generates swagger documents
“google is not defined” when using Google Maps V3 in Firefox remotely
SSH 远程执行命令简介
How many convolution methods does deep learning have? (including drawings)
Torch learning notes (5) -- autograd
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]