当前位置:网站首页>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 :

边栏推荐
- Should enterprises start building progressive web applications?
- Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
- Skku| autonomous handover decision of UAV Based on deep reinforcement learning
- Is Shengang securities company as safe as other securities companies
- Force buckle day32
- [typora installation package] old typera installation package, free version
- 2022 R2 mobile pressure vessel filling certificate examination and R2 mobile pressure vessel filling simulation examination questions
- Portable two-way radio equipment - current market situation and future development trend
- 0 basic learning C language - nixie tube dynamic scanning display
- Day05 branch and loop (II)
猜你喜欢

String hash, find the string hash value after deleting any character, double hash

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?

Maximum likelihood method, likelihood function and log likelihood function

Douban scoring applet Part-3

Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files

Introduction to Tianchi news recommendation: 4 Characteristic Engineering
![[turn] solve the problem of](/img/c2/368582a8ed26254409fe391899ba41.jpg)
[turn] solve the problem of "RSA public key not find" appearing in Navicat premium 15 registration

How to use AHAS to ensure the stability of Web services?

Applet graduation project based on wechat selection voting applet 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]](/img/8b/ff062f34d36e1caa9909c8ab431daf.jpg)
Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]
随机推荐
MySQL -- Introduction and use of single line functions
C import Xls data method summary III (processing data in datatable)
The force deduction method summarizes the single elements in the 540 ordered array
Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
Ka! Why does the seat belt suddenly fail to pull? After reading these pictures, I can't stop wearing them
Avoid playing with super high conversion rate in material minefields
Setting function of Jerry's watch management device [chapter]
Small program graduation project based on wechat reservation small program graduation project opening report reference
2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
Hbuilder link Xiaoyao simulator
Will the memory of ParticleSystem be affected by maxparticles
Chinese Mitten Crab - current market situation and future development trend
Idsia & supsi & usi | continuous control behavior learning and adaptive robot operation based on Reinforcement Learning
The contact data on Jerry's management device supports reading and updating operations [articles]
Sequence sorting of basic exercises of test questions
Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
Douban scoring applet Part-3
Solution of cursor thickening
Gee: create a new feature and set corresponding attributes
Idea if a class cannot be found, it will be red