当前位置:网站首页>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 :
边栏推荐
- 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.
- Who moved my code!
- Special copy UML notes
- [leetcode daily question] a single element in an ordered array
- 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
- Gnupg website
- Logical operator, displacement operator
- How to delete MySQL components using xshell7?
- MySQL - use of aggregate functions and group by groups
- All ceramic crowns - current market situation and future development trend
猜你喜欢
Basic editing specifications and variables of shell script
TP5 automatic registration hook mechanism hook extension, with a complete case
How programmers find girlfriends through blind dates
Pyinstaller packaging py script warning:lib not found and other related issues
Lightweight Pyramid Networks for Image Deraining
Setting function of Jerry's watch management device [chapter]
2020-12-02 SSM advanced integration Shang Silicon Valley
Introduction to Tianchi news recommendation: 4 Characteristic Engineering
From the 18th line to the first line, the new story of the network security industry
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
随机推荐
LeetCode226. Flip binary tree
2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
MySQL introduction - functions (various function statistics, exercises, details, tables)
Which insurance products can the elderly buy?
Who moved my code!
MySQL -- Introduction and use of single line functions
Huawei cloud micro certification Huawei cloud computing service practice has been stable
Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
Idsia & supsi & usi | continuous control behavior learning and adaptive robot operation based on Reinforcement Learning
be based on. NETCORE development blog project starblog - (14) realize theme switching function
Containerization technology stack
Writeup (real questions and analysis of ciscn over the years) of the preliminary competition of national college students' information security competition
Future source code view -juc series
Avoid playing with super high conversion rate in material minefields
Cancer biopsy instruments and kits - market status and future development trends
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
File contains vulnerability summary
String hash, find the string hash value after deleting any character, double hash
Force buckle day32
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?