当前位置:网站首页>MySQL advanced SQL statement of database (1)
MySQL advanced SQL statement of database (1)
2022-06-30 10:16:00 【thengsd】
Catalog
- One 、MySQL High level statements
- 1、SELECT— Display all data of one or more fields in the table
- 2、DISTINCT— Don't show duplicate data
- 3、WHERE— Conditional query
- 4、AND|OR------ And | or
- 5、IN— Display information about known values
- 6、BETWEEN— Displays data in two ranges
- 7、 wildcard
- 8、LIKE— Match a pattern to find out what we want
- 9、ORDER BY------ Sort by keyword
- 10、 function
- 11、GROUP BY— Yes GROUP BY Summarize and group the query results in the following fields
- 12、HAVING— Used to filter by GROUP BY Statement returns a record table
- 13、 Alias — Field alias , Table alias
- 14、 Subquery : Connect tables
- 15、EXISTS— It is used to test whether the inner query produces any results
- Two 、 Link query
- 3、 ... and 、CREATE VIEW View
One 、MySQL High level statements
1、SELECT— Display all data of one or more fields in the table


2、DISTINCT— Don't show duplicate data

3、WHERE— Conditional query

4、AND|OR------ And | or

5、IN— Display information about known values

6、BETWEEN— Displays data in two ranges

7、 wildcard
- Usually, wildcards are used with LIKE Used together
- % : A percent sign means zero 、 One or more characters
- _ : The underline represents a single character
8、LIKE— Match a pattern to find out what we want

9、ORDER BY------ Sort by keyword

10、 function
(1) Mathematical functions
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
least(x1,x2…) Returns the smallest value in the set
SELECT abs(-1), rand(), mod(5,3), power(2,3), round(1.89);
SELECT round(1.8937,3), truncate(1.235,2), ceil(5.2), floor(2.1), least(1.89,3,6.1,2.1);

(2) Aggregate functions
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
#count(*) Including the number of rows of all columns , When it comes to statistical results , The value of... Is not ignored NULL
#count( Name ) The number of rows in the column that includes only the column name , When it comes to statistical results , Column values of NULL The line of
example :
select avg(sales) from info;
select count(place_name) from info;
select count(distinct place_name) from info;
select max(sales) from info;
select min(sales) from info;
select sum(sales) from info;


(3) String function
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
- Add : Such as sql_mode Open... Open PIPES_AS_CONCAT,"||" 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

- 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

11、GROUP BY— Yes GROUP 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 .


12、HAVING— Used to filter by GROUP BY Statement returns a record table
- 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 .

13、 Alias — Field alias , Table alias

14、 Subquery : Connect tables
- Son WHERE Clause or HAVING Clause to insert another SQL sentence



15、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 not , The whole SQL Statement will not produce any results .

Two 、 Link query
1、inner join( It's equivalent )
- Only rows with equal join fields in two tables are returned

2、left join( Left join )
- Returns records that include all records in the left table and join fields in the right table

3、right join( Right link )
- Returns records that include all records in the right table and join fields in the left table

3、 ... and 、CREATE VIEW View
- The difference between a view and a table is , There is the actual stored information in the form , And a view is a structure built on a table , It doesn't actually store data itself .
- The temporary table disappears automatically when the user exits or loses the connection to the database , And the view doesn't disappear .
- Views don't contain data , Just store its definition , Its purpose is to simplify complex queries . For example, you need to query several tables , But also to carry out statistical sorting and other operations , Write SQL Sentences can be cumbersome , Join several tables with views , Then query the view , Just like querying a table , Very convenient .


边栏推荐
猜你喜欢

How to build an all-in-one database cloud machine that meets the needs of information innovation?

About Jul
![[JVM] brief introduction to CMS](/img/4e/df4a193eed39438f808059f67f19a1.png)
[JVM] brief introduction to CMS
![[JVM] G1 garbage collector](/img/fc/ea1f8cee0f207e4a5c804f88f2871c.png)
[JVM] G1 garbage collector

光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述

Theme Studio(主题工作室)

South China Industrial Group launched digital economy and successfully held the city chain technology conference

鼠标右键打开cmd(命令行)

2022第六季完美童模 合肥赛区 初赛圆满落幕

无人机项目跟踪记录八十三---pcb图完成
随机推荐
栈题目:字符串解码
Shell script multi loop experiment
ModuleNotFoundError: No module named ‘_ swigfaiss‘
"Kunming City coffee map" activity was launched again
About Jul
Automated stock trading ensemble strategy based on Reinforcement Learning
“昆明城市咖啡地图”活动再度开启
Detailed explanation of SolidWorks mass characteristics (inertia tensor, moment of inertia, inertia spindle)
采坑:Didn‘t receive robot state (joint angles) with recent timestamp within 1 seconds.
Right click to open CMD (command line)
How can we have high performance and simple agility in the enterprise cloud on oracle?
关于字符串的split和join操作
力扣 428. 序列化和反序列化 N 叉树 DFS
Plan the IT technology route for the new year? Let's learn about Gartner infrastructure hype cycle
South China Industrial Group launched digital economy and successfully held the city chain technology conference
2021-07-26
Add / delete query of topic
“昆明城市咖啡地图”活动再度开启
李沐《动手学习深度学习》d2lbook环境搭建
乡村振兴公益基金启动暨古茶树非遗保护公益行发布