当前位置:网站首页>Mysql database easy learning 06 - commonly used by data analysts: single table query of data query language DQL
Mysql database easy learning 06 - commonly used by data analysts: single table query of data query language DQL
2022-06-22 01:58:00 【Smart Aries】
Data query language DQL
Used to query records in database tables
The basic structure :
SELECT Field name FROM Table or view name WHERE Query criteria
Single table query
1、 The result is a virtual result set
select After the statement is executed, the server will retrieve the data in the table as required , And send the search results to the client , This temporary result set in the form of a table , It is Store in memory , Not on disk , After performing other operations, the result set is gone , So it is A temporary virtual result set , Not a real table .
2、 A full table query
select * from Table name ;
If a table has a large volume , Generally, the following two methods are used to view the data in the table
1、 Choose the former 10 Row to view top 10
select top 10 * from Table name
2、 Limit the number of query results limit
select Field 1[, Field 2,…] from Table name limit [ Offset ,] Row number ;
limit Accept One or two numbers Parameters , Argument must be an integer constant
The first parameter specifies the offset of the first return record line , The second parameter specifies the maximum number of rows to return records
If only one parameter is given , Indicates the maximum number of record lines returned
The offset of the initial record line is 0( instead of 1)
Example :
dept There is a total of 4 Row data 


3、 Query specified column
select Field 1[, Field 2,…] from Table name ;
4、 Query non duplicate data distinct
select distinct Field name from Table name ;
5、 Set alias as
select Field name as Column alias from Original table name [as ] Table alias ;
6、 Conditions of the query where
select Field 1[, Field 2,…] from Table name where filter ;
You can add... To the filter criteria Operator :
Arithmetic operator :
+ Add ; - reduce ;* ride ; / except
Comparison operator :
= be equal to ;>/>= Greater than / Greater than or equal to ;</<= Less than / Less than or equal to ;
!=/<> It's not equal to ;
between…and… Between what
Logical operators
and And ;or or ;not Not
7、 Null value query is null
select Field 1[, Field 2,…] from Table name where Null value field is[not] null;
Be careful : Null values cannot be compared , If you want to filter out null values, you should use is null
8、 Fuzzy query like wildcard
select Field 1[, Field 2,…] from Table name where String field [ not] like wildcard ;
wildcard :
Percent sign (%) wildcard : matching 0 Characters or more
Underline (_) wildcard : Match a character
9、 Aggregate operations
Aggregate multiple rows of data into one row
The aggregate function will do null Other data Aggregate operations 
10、 Grouping query and grouping filter
Group query :
select Field 1[, Field 2,…] from Table name [ where Query criteria ] group by Grouping field 1[, Grouping field 2,…];
Group query results by one or more fields , The fields with the same value are a set of , Aggregate each group
When grouping multiple fields , Multiple fields with exactly the same value will be divided into a group
Filter after grouping :
select Field 1[, Field 2,…] from Table name [ where Query criteria ][ group by Grouping field 1[, Grouping field 2,…]] having filter ;
where And having The difference between :
where In grouping and aggregation Computing Before Filter the data in the table , and having In grouping and aggregation after Filter the divided groups , therefore where Clause cannot contain aggregate function .
11、 Sorting of query results order by
select Field 1[, Field 2,…] from Table name order by Field 1[ Sort direction , Field 2 Sort direction ,…];
Sort query results by one or more fields , When sorting, you can specify the sorting direction for each field . When sorting multiple fields , First, sort by the first field , If the first field has the same value, sort by the second field
Specify sorting direction :
asc( ascendent) Ascending , for example [ 0 1 2 3 4 5 ];
desc(descendent) Descending , for example [ 5 4 3 2 1 0 ]
边栏推荐
- 阿里腾讯百度软件测试工程师推荐——软件测试模型之快速原型模型
- 产业互联网时代,并不存在真正意义上的中心
- BSV上的委托合约(3)
- Google Earth Engine(GEE)——合并VCI指数和TCI温度得时序影像折线图(危地马拉、萨尔瓦多为例)
- Dachang NVIDIA face test questions sorting 123
- Pyechart drawing word cloud
- The way to build the efficiency platform of didi project
- 【第 13 章 基于霍夫曼图像压缩重建--Matlab深度学习实战图像处理应用】
- acwing 838. Heap sort (write a heap)
- sql server递归查询
猜你喜欢

Five years after graduation, I finally became a software testing engineer with a monthly salary of 13000

Leetcode + 46 - 50

阿里,腾讯,百度软件测试工程师推荐——软件测试模型之瀑布模型

acwing 838. Heap sort (write a heap)

【虚幻引擎UE】打包报错出现!FindPin错误的解决办法

Commission contract on BSV (2)

【第 15 章 基于小波的图像压缩技术深度学习机器学习的图像处理应用matlab.】

Heidisql always makes errors when inserting data. What should I do

MBA-day23 至多至少问题-练习题

Test case design method -- cause and effect diagram method
随机推荐
Pytoch neural network [handwritten digit recognition]
acwing 838. Heap sort (write a heap)
第 18 章 基于GUI搭建通用视频处理工具matlab应用GUI实现
[amd comprehensive job search experience sharing 618]
heidisql 插入数据老是出错,怎么办
Commission contract on BSV (2)
Test APK exception control WiFi scan attacker development
第 12 章 基于块匹配的全景图像拼接--Matlab深度学习实战图像处理应用
flutter系列之:flutter中的IndexedStack
How to restore the IE browser auto jump edge
ShardingSphere-proxy-5.0.0分布式哈希取模分片实现(四)
Ansible 配置文件
The sandbox has reached a cooperation with Time magazine to establish "New York Times Square" in metauniverse
阿里腾讯百度软件测试工程师推荐——软件测试模型之快速原型模型
第 03 章 基于多尺度形态学提取眼前节组织-全套系统MATLAB智能驾驶深度学习
光照相关 shader
LeetCode+ 46 - 50
acwing 836. 合并集合 (并查集)
acwing 835. Trie string statistics
【第 15 章 基于小波的图像压缩技术深度学习机器学习的图像处理应用matlab.】