当前位置:网站首页>MySQL advanced (Advanced) SQL statement (I)
MySQL advanced (Advanced) SQL statement (I)
2022-07-04 01:51:00 【Richard_ Chiang】
MySQL senior ( Advanced )SQL sentence ( One )
Case study :
One 、MySQL High level statements
1、SELECT------ Display all data of one or more fields in the table
2、DISTINCT------ Don't show duplicate data
3、WHERE------ Conditional query
4、AND OR------ And or
5、IN------ Display information about known values
6、BETWEEN------ Displays data in two ranges
7、 wildcard
- Usually, wildcards are used with LIKE Used together
8、LIKE------ Match a pattern to find out what we want
9、ORDER BY------ Sort by keyword
10、 function
(1) Mathematical functions
(2) Aggregate functions
(3) String function
Add : Such as sql_mode Open... Open PIPES_AS_CONCAT,"||" Treat as the concatenation operator of a string, not as the or operator , And string splicing function Concat Similar , This sum Oracle The database is used in the same way
trim() Returns a value with the specified format removed
- concat(x,y) The parameters that will be provided x and y Concatenate into a string
- substr(x,y) Get from string x No y A string starting at a position , Follow substring() Functions work the same
- substr(x,y,z) Get from string x No y The starting length of a position is z String
- length(x) Return string x The length of
- replace(x,y,z) The string z Alternative string x String in y
- upper(x) The string x All of the letters of the alphabet become capital letters
- lower(x) The string x All of the letters of the are changed into lower case letters
- left(x,y) Return string x Before y Characters
- right(x,y) Return string x After y Characters
- repeat(x,y) The string x repeat y Time
- space(x) return x A space
- strcmp(x,y) Compare x and y, The value returned can be -1,0,1
- reverse(x) The string x reverse
11、GROUP BY------ Yes GROUP BY Summarize and group the query results in the following fields
- Usually used in combination with aggregate functions
- GROUP BY There is a principle , Namely SELECT In all the following columns , Columns that do not use aggregate functions , Must appear in GROUP BY Back .
12、HAVING------ Used to filter by GROUP BY Statement returns a record table ( result )
- Usually with GROUP BY Statements are used in conjunction with
- HAVING The existence of sentences makes up for WHERE Keywords cannot be combined with aggregate functions . If you are SELECT Only the function bar , Then there is no need for GROUP BY Clause .
13、 Alias ------ Field alias , Table alias
14、 Subquery : Connect tables
- Son WHERE Clause or HAVING Clause to insert another SQL sentence
15、EXISTS------ It is used to test whether the inner query produces any results
- Whether Boolean value is true or not
- If any , The system will execute the SQL sentence . If not , The whole SQL Statement will not produce any results .
Two 、 Link query
1、inner join( It's equivalent )
- Only rows with equal join fields in two tables are returned
2、left join( Left join )
- Returns records that include all records in the left table and join fields in the right table
3、right join( Right link )
- Returns records that include all records in the right table and join fields in the left table
3、 ... and 、CREATE VIEW View
- The difference between a view and a table is , There is the actual stored information in the form , And a view is a structure built on a table , It doesn't actually store data itself .
- The temporary table disappears automatically when the user exits or loses the connection to the database , And the view doesn't disappear .
- Views don't contain data , Just store its definition , Its purpose is to simplify complex queries . For example, you need to query several tables , But also to carry out statistical sorting and other operations , Write SQL Sentences can be cumbersome , Join several tables with views , Then query the view , Just like querying a table , Very convenient .
summary :
- View tables are not like temporary tables , Automatically disappear after disconnection
- The view table saves select Statement query results , It doesn't store data itself
- When the structure of the view chart is the same as that of the original table storing data, you can modify or insert data , If not, you cannot modify or insert data ( For example, the results of multi table join queries )
边栏推荐
- Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.
- JVM performance tuning and practical basic theory - medium
- Human resource management online assignment
- Which insurance products can the elderly buy?
- Three layer switching ①
- It's corrected. There's one missing < /script >, why doesn't the following template come out?
- Conditional test, if, case conditional test statements of shell script
- Flex flexible layout, box in the middle of the page
- How can enterprises optimize the best cost of cloud computing?
- Basic editing specifications and variables of shell script
猜你喜欢
From the 18th line to the first line, the new story of the network security industry
Small program graduation project based on wechat examination small program graduation project opening report function reference
What are the advantages and disadvantages of data center agents?
Gee: create a new feature and set corresponding attributes
The automatic control system of pump station has powerful functions and diverse application scenarios
Openbionics robot project introduction | bciduino community finishing
Install the pit that the electron has stepped on
The reasons why QT fails to connect to the database and common solutions
JVM performance tuning and practical basic theory - medium
Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
随机推荐
Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends
Containerization technology stack
Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
Huawei cloud micro certification Huawei cloud computing service practice has been stable
Small program graduation project based on wechat examination small program graduation project opening report function reference
Gee: create a new feature and set corresponding attributes
Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference
Méthode de calcul de la connexion MSSQL de la carte esp32c3
Openbionics exoskeleton project introduction | bciduino community finishing
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
HackTheBox-baby breaking grad
What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
How programmers find girlfriends through blind dates
Introduction to superresolution
Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
Jerry's watch information type table [chapter]
Reading notes - learn to write: what is writing?
MySQL statement learning record
All ceramic crowns - current market situation and future development trend