当前位置:网站首页>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 :
边栏推荐
- All ceramic crowns - current market situation and future development trend
- Is Shengang securities company as safe as other securities companies
- Pyrethroid pesticide intermediates - market status and future development trend
- ThinkPHP uses redis to update database tables
- Small program graduation project based on wechat examination small program graduation project opening report function reference
- Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]
- LeetCode 168. Detailed explanation of Excel list name
- Should enterprises start building progressive web applications?
- Openbionics robot project introduction | bciduino community finishing
- Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
猜你喜欢
Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
How to delete MySQL components using xshell7?
Idea if a class cannot be found, it will be red
String & memory function (detailed explanation)
Life cycle of instance variables, static variables and local variables
Openbionics exoskeleton project introduction | bciduino community finishing
Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
Luogu p1309 Swiss wheel
How to use AHAS to ensure the stability of Web services?
Write the first CUDA program
随机推荐
2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
Huawei BFD and NQA
Openbionics exoskeleton project introduction | bciduino community finishing
All metal crowns - current market situation and future development trend
Bacteriostatic circle scanning correction template
Lightweight Pyramid Networks for Image Deraining
Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
Idsia & supsi & usi | continuous control behavior learning and adaptive robot operation based on Reinforcement Learning
Special copy UML notes
Prose article appreciation - the rain in the warm country has never changed into cold, hard and brilliant flowers. Knowledgeable people think he is monotonous, and he thinks he is unlucky, doesn't he?
Use classname to modify style properties
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
Mongodb learning notes: command line tools
Mobile phone battery - current market situation and future development trend
The latest analysis of hoisting machinery command in 2022 and free examination questions of hoisting machinery command
2022 new examination questions for safety management personnel of hazardous chemical business units and certificate examination for safety management personnel of hazardous chemical business units
[typora installation package] old typera installation package, free version
A little understanding of GSLB (global server load balance) technology
Idea if a class cannot be found, it will be red
JVM performance tuning and practical basic theory - medium