当前位置:网站首页>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 .
边栏推荐
- 浏览器复制的网址粘贴到文档是超链接
- 将小程序容器技术应用到物联网IoT生态建设中
- Brève description du collecteur d'ordures G1
- Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home
- 二极管如何工作?
- Stack Title: String decoding
- 【C语言快速上手】带你了解C语言,零基础入门③
- Financial private cloud infrastructure scheme evaluation (Architecture and storage)
- L'activité "Kunming City coffee map" a rouvert
- 一些国内镜像源
猜你喜欢
二极管如何工作?
陈颢天 荣获第七届少儿模特明星盛典全国总决赛 全国总冠军
Plan the IT technology route for the new year? Let's learn about Gartner infrastructure hype cycle
Flume learning 1
华南产业集团发力数字经济,城链科技发布会成功召开
Installing Oracle database process in windows2007 on VM
South China Industrial Group launched digital economy and successfully held the city chain technology conference
Flume learning II - Cases
打通供应链 深圳礼品展助跨境电商寻破局之道
机器人系统动力学——惯性参数
随机推荐
MIT-6874-Deep Learning in the Life Sciences Week5
机械臂速成小指南(四):机械臂关键部件之减速机
Js获取指定字符串指定字符位置&指定字符位置区间的子串【简单详细】
GNN hands on practice (II): reproduction graph attention network gat
Applying applet container technology to IOT ecological construction
How do databases go to the enterprise cloud? Click to view the answer
Setting up the d2lbook environment for Li Mu's "hands on learning and deep learning"
Enterprise data center "cloud" transformation solution
[JVM] G1 garbage collector
机械臂速成小指南(五):末端执行器
Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home
How to build a private cloud and create a hybrid cloud ecosystem?
About Jul
Network based dynamic routing protocol (OSPF)
栈题目:字符串解码
Magnetic levitation 3D lamp
keras ‘InputLayer‘ object is not iterable
GNN动手实践(二):复现图注意力网络GAT
Shenhe thermomagnetic: Super fusion dual active cluster solution for MES system
事件委托的使用与说明》