当前位置:网站首页>SQL learning notes (I)
SQL learning notes (I)
2022-07-03 12:53:00 【ElsaWu1998】
( This article is being updated )
Some great advanced tutorials
- SQL Advanced techniques https://zhuanlan.zhihu.com/p/139856374
Include content :SQL The writing standard of 、SQL Some advanced use skills of ( Skillfully use CASE WHEN Make statistics & to update 、 Skillfully use HAVING Clause 、 Self join 、 Skillfully use COALESCE function )、SQL Performance optimization skills . - mysql Video combat tutorial online learning - database - Frog lesson net https://www.wkcto.com/courses.html?list=mysql
Some points to think about when brushing questions
I want to master it recently SQL, But undergraduate teachers teach relatively shallow , And most of them have been forgotten , So I finished it in one day SQL Basic tutorials for , Here is an easy-to-use self-study SQL Website ( It can run in real time ): self-taught SQL network . At the same time, I also did a little practice LeetCode
This article will record the important points in the learning process , For future study reference .
Pay attention to the writing order . The typical correct sequence is as follows :
SELECT DISTINCT column, AGG_FUNC(column_or_expression) FROM mytable JOIN another_table ON mytable.column = another_table.column WHERE constraint_expression GROUP BY column HAVING constraint_expression ORDER BY column ASC/DESC LIMIT count OFFSET COUNT;
If you don't have to
GROUP BY
grammar , ordinaryWHERE
That's enough. .If you want to separate statistics according to two dimensions , stay
GROUP BY
Just put two inside . for example :select role,count(*),(case when Building is not null then 1 else 0 end) bn from employees group by role,bn
Query execution order :
FROM
andJOIN
;WHERE
;GROUP BY
;HAVING
;SELECT
;DISTINCT
If there are duplicate data rows DISTINCT Will be responsible for weight removal .ORDER BY
When the result set is determined ,ORDER BY Sort the results . because SELECT The expression in has been executed . You can use AS Alias .LIMIT / OFFSET
Last LIMIT and OFFSET Intercept some data from the sorting results .When selecting the highest data , If you need to display a null value , have access to
IFNULL(...,NULL)
LIMIT The parameter of cannot be a formula , If you need to change a value, you can use the statement
SET N = N-1;
If you need to update the table , Can cooperate withUPDATE
Use . for example :UPDATE Salaries SET salary = CASE WHEN salary >= 10000 THEN salary * 0.9 WHEN salary < 10000 THEN salary * 1.2 ELSE salary END;
边栏推荐
- 阿里 & 蚂蚁自研 IDE
- Dojo tutorials:getting started with deferrals source code and example execution summary
- C graphical tutorial (Fourth Edition)_ Chapter 17 generic: genericsamplep315
- 双链笔记·思源笔记综合评测:优点、缺点、评价
- Differences and connections between final and static
- The latest version of blind box mall thinkphp+uniapp
- Comprehensive evaluation of double chain notes · Siyuan notes: advantages, disadvantages and evaluation
- Record your vulnhub breakthrough record
- Write a simple nodejs script
- 电压环对 PFC 系统性能影响分析
猜你喜欢
Ali & ant self developed IDE
T430 toss and install OS majave 10.14
【数据库原理及应用教程(第4版|微课版)陈志泊】【SQLServer2012综合练习】
最新版抽奖盲盒运营版
2021 autumn Information Security Experiment 1 (password and hiding technology)
Application of ncnn Neural Network Computing Framework in Orange Pi 3 Lts Development Board
Xctf mobile--app1 problem solving
【数据库原理及应用教程(第4版|微课版)陈志泊】【第六章习题】
Leetcode234 palindrome linked list
强大的头像制作神器微信小程序
随机推荐
idea将web项目打包成war包并部署到服务器上运行
CNN MNIST handwriting recognition
Leetcode234 palindrome linked list
ncnn神經網絡計算框架在香柳丁派OrangePi 3 LTS開發板中的使用介紹
How to convert a decimal number to binary in swift
Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
The foreground uses RSA asymmetric security to encrypt user information
低代码平台国际化多语言(i18n)技术方案
Huffman coding experiment report
It feels great to know you learned something, isn‘t it?
基于Linu开发的项目视频
OpenStack节点地址改变
Sword finger offer05 Replace spaces
Nodejs+Express+MySQL实现登陆功能(含验证码)
Quickly learn member inner classes and local inner classes
GCN thinking - word2vec directly calculates text classification
如何在微信小程序中获取用户位置?
Kotlin notes - popular knowledge points asterisk (*)
Xctf mobile--app2 problem solving
Create a dojo progress bar programmatically: Dojo ProgressBar