当前位置:网站首页>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 :
边栏推荐
- The difference between lambda expressions and anonymous inner classes
- LeetCode 168. Detailed explanation of Excel list name
- What are the advantages and disadvantages of data center agents?
- G3 boiler water treatment registration examination and G3 boiler water treatment theory examination in 2022
- Reading notes - learn to write: what is writing?
- C import Xls data method summary II (save the uploaded file to the DataTable instance object)
- SQL statement
- Why can't it run (unresolved)
- Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment
- A fan summed up so many interview questions for you. There is always one you need!
猜你喜欢
Solution of cursor thickening
Idea if a class cannot be found, it will be red
Pyinstaller packaging py script warning:lib not found and other related issues
Use classname to modify style properties
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
Feign implements dynamic URL
What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
Basic editing specifications and variables of shell script
[leetcode daily question] a single element in an ordered array
Maximum entropy model
随机推荐
Why can't it run (unresolved)
Portable two-way radio equipment - current market situation and future development trend
Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
ThinkPHP uses redis to update database tables
2022 R2 mobile pressure vessel filling certificate examination and R2 mobile pressure vessel filling simulation examination questions
A little understanding of GSLB (global server load balance) technology
Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
LeetCode226. Flip binary tree
JVM performance tuning and practical basic theory - medium
Flex flexible layout, box in the middle of the page
Remember a lazy query error
Day05 table
Trading software programming
The automatic control system of pump station has powerful functions and diverse application scenarios
2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
Solution to the problem that jsp language cannot be recognized in idea
2020-12-02 SSM advanced integration Shang Silicon Valley
How to delete MySQL components using xshell7?
MPLS③