当前位置:网站首页>Database - MySQL advanced SQL statement (I)
Database - MySQL advanced SQL statement (I)
2022-07-01 18:15:00 【Enthusiastic masses】
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
- (1) Mathematical functions
- (2) Aggregate functions
- (3) String 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
Study preparation
Create two tables first , For sentence experiment
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
8、LIKE------ Match a pattern to find out what we want
9、ORDER BY------ Sort by keyword
10、 function
(1) Mathematical functions
(2) Aggregate functions
(3) String function
- 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
Less than -1, Is equal to 0, Greater than 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
example 1:
example 2:
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 .
边栏推荐
- Software construction scheme of smart factory collaborative management and control application system
- Unity3d extended toolbar
- Openlayers customize bubble boxes and navigate to bubble boxes
- Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
- transform. Forward and vector3 Differences in the use of forward
- Redis -- data type and operation
- Record 3 - the state machine realizes key control and measures the number of external pulses
- MES production equipment manufacturing execution system software
- The difference and relationship between iteratible objects, iterators and generators
- js如何将带有分割符的字符串转化成一个n维数组
猜你喜欢
Domestic spot silver should be understood
Petrv2: a unified framework for 3D perception of multi camera images
June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries
Euler function: find the number of numbers less than or equal to N and coprime with n
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Cassette helicopter and alternating electric field magnetic manometer DPC
Penetration practice vulnhub range Tornado
Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
Happy new year | 202112 monthly summary
随机推荐
聊聊项目经理最爱使用的工具
Is Huishang futures a regular futures platform? Is it safe to open an account in Huishang futures?
The new server is packaged with the source code of H5 mall with an operation level value of several thousand
MES production equipment manufacturing execution system software
On the language internationalization of Yongzhong Office
Nielseniq found that 60% of the re launched products had poor returns
js如何将带有分割符的字符串转化成一个n维数组
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
Kernel stray cat stray dog pet adoption platform H5 source code
Basic usage of shell script
线上开通ETF基金账户安全吗?有哪些步骤?
Redis master-slave realizes 10 second check and recovery
transform. Forward and vector3 Differences in the use of forward
Htt [ripro network disk link detection plug-in] currently supports four common network disks
ACL 2022 | decomposed meta learning small sample named entity recognition
开发那些事儿:EasyCVR平台添加播放地址鉴权
目前炒期货在哪里开户最正规安全?怎么期货开户?
JS how to convert a string with a delimiter into an n-dimensional array
Apache iceberg source code analysis: schema evolution
Software construction scheme of smart factory collaborative management and control application system