当前位置:网站首页>High level application of SQL statements in MySQL database (I)
High level application of SQL statements in MySQL database (I)
2022-07-04 01:49:00 【Guyu Taoist priest】
Table of Contents
- One 、 Get ready
- 2. Create two tables as examples
- Two 、SQL Statement high-level use
- 1.SELECT
- 2.DISTINCT
- 3.WHERE
- 4.AND、OR
- 5.IN
- 6.BETWEEN
- 7. wildcard (LIKE)
- 8.ORDER BY
- 3、 ... and 、 function
- 1. Mathematical functions
- 2. Aggregate functions
- 4.'||' Connector
- 5.GROUP BY
- 6.HAVING
- 7. Alias
- 9.EXISTS
- 10. Link query
One 、 Get ready
1. Source code compilation and installation MySQL
Mysql service ( One key deployment )
2. Create two tables as examples
Two 、SQL Statement high-level use
1.SELECT
Display all the data of one or more fields in the table
usage :
2.DISTINCT
Don't show duplicate data , And weight removal
usage :
3.WHERE
Conditional query
usage :
4.AND、OR
And or
usage :
5.IN
Show known data
usage :
6.BETWEEN
Displays data in two ranges
usage :
7. wildcard (LIKE)
Usually, wildcards are used with LIKE Use it together
%: A percent sign means zero 、 One or more characters
_: The underline represents a single character
LIKE: Used to match patterns to find data
usage :
8.ORDER BY
Sort by keyword
usage :
3、 ... and 、 function
1. Mathematical functions
The specific usage is shown in the table below :
function | explain |
---|---|
abs(x) | return x The absolute value of |
rand() | return 0 To 1 The random number |
mod(x,y) | return x Divide y The remainder after |
power(x,y) | return x Of y Power |
round(x) | Return from x The nearest integer |
round(x,y) | Retain x Of y The rounded value of a decimal place |
sqrt(x) | return x The square root of |
truncate(x,y) | Return to digital x Truncated to y A decimal value |
ceil(x) | Returns greater than or equal to x Minimum integer of |
floor(x) | Returns less than or equal to x Maximum integer for |
greatest(x1,x2…) | Returns the maximum value in the collection |
east(x1,x2…) | Returns the smallest value in the set |
example :
2. Aggregate functions
The specific usage is shown in the table below :
function | explain |
---|---|
avg() | Returns the average value of the specified column |
count() | Returns the value of the specified column NULL The number of values |
min() | Returns the minimum value of the specified column |
max() | Returns the maximum value of the specified column |
sum(x) | Returns the sum of all values in the specified column |
example :
3. String function
function | explain |
---|---|
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 |
- [ Location ]: The value of can be LEADING ( At first ), TRAILING ( ending ), BOTH ( The beginning and the end )
- [ The string to remove ]: From the beginning of the string 、 ending , Or a string removed from the beginning and end ; The default is space
- example :
4.'||' Connector
If in mysql In the configuration file ,sql_mode Open... Open PIPES_AS_CONCAT, be "||" 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
5.GROUP BY
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
usage :
6.HAVING
Used to filter by GROUP BY Statement returned recordset , 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
usage :
7. Alias
Used for field alias and table alias
usage :
8. Subquery
Connect tables , stay WHERE Clause or HAVING Clause to insert another SQL sentence
9.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 it were not so , The whole SQL Statement will not produce any results
usage :
10. Link query
10.1 inner join—— It's equivalent
Returns only rows with equal join fields in two tables
usage :
10.2 left join—— Left join
Returns records that include all records in the left table and join fields in the right table
example :
10.3 right join—— Right link
Returns records including all records in the right table and the same join field in the left table
example :
边栏推荐
- Introduction to superresolution
- MySQL statement learning record
- Huawei cloud micro certification Huawei cloud computing service practice has been stable
- Why is the operation unsuccessful (unresolved) uncaught syntaxerror: invalid or unexpected token (resolved)
- be based on. NETCORE development blog project starblog - (14) realize theme switching function
- 0 basic learning C language - nixie tube dynamic scanning display
- Development of user-defined navigation bar in uniapp
- When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
- When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
- Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
猜你喜欢
Install the pit that the electron has stepped on
How to use AHAS to ensure the stability of Web services?
Ka! Why does the seat belt suddenly fail to pull? After reading these pictures, I can't stop wearing them
Will the memory of ParticleSystem be affected by maxparticles
The automatic control system of pump station has powerful functions and diverse application scenarios
Solution to the problem that jsp language cannot be recognized in idea
SRCNN:Learning a Deep Convolutional Network for Image Super-Resolution
JVM performance tuning and practical basic theory - medium
Small program graduation project based on wechat reservation small program graduation project opening report reference
JVM performance tuning and practical basic theory - medium
随机推荐
Notice on Soliciting Opinions on the draft of information security technology mobile Internet application (APP) life cycle security management guide
Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference
Example 072 calculation of salary it is known that the base salary of an employee of a company is 500 yuan. The amount of software sold by the employee and the Commission method are as follows: Sales
Introduction to superresolution
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]
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.
Neo4j learning notes
What are the advantages and disadvantages of data center agents?
2020-12-02 SSM advanced integration Shang Silicon Valley
SQL statement
Logical operator, displacement operator
JVM performance tuning and practical basic theory - medium
Some other configurations on Huawei's spanning tree
The force deduction method summarizes the single elements in the 540 ordered array
MySQL statement learning record
Mongodb learning notes: command line tools
Typescript basic knowledge sorting
Write the first CUDA program
Idsia & supsi & usi | continuous control behavior learning and adaptive robot operation based on Reinforcement Learning
Functions and arrays of shell scripts