当前位置:网站首页>Explain the three ways to remove duplicate data in MySQL
Explain the three ways to remove duplicate data in MySQL
2022-06-09 13:46:00 【1024 Q】
One 、 background
Two 、 Three methods of data De duplication are used
1. adopt MySQL DISTINCT: duplicate removal ( Filter duplicate data )
2.group by
3.row_number Window function
3、 ... and 、 summary
One 、 backgroundRecently, I have been conducting data joint debugging with the system module , One of the requirements is that the relevant data under the two roles After comparison, the latest data will be returned , So I thought of the weight removal , Make a summary again .
Two 、 Three methods of data De duplication are used
1.1. In the use of mysql SELECT Statement returns all matching rows when querying data .
SELECT t.age FROM t_user t
You can see that the query result returns 10 Bar record , There are some repetitive age value , Sometimes out of the requirements of data analysis , Record values that need to be de duplicated .
1.2.DISTINCT Key indication MySQL Eliminate duplicate record values .
The grammar format is :
SELECT DISTINCT < Field name > FROM < Table name >;
SELECT DISTINCT t.age FROM t_user tIt can be seen from the running results that , The query result only returns 5 Bar record age value , And there are no duplicate values .
ps:
among ,“ Field name ” Name the field to be de duplicated , Multiple fields are separated by commas .
Use DISTINCT You should pay attention to the following points when using keywords :
DISTINCT Keywords can only be found in SELECT Use in statement .
When de duplicating one or more fields ,DISTINCT Keywords must be at the top of all fields .
If DISTINCT There are multiple fields after the keyword , Multiple fields will be combined to remove duplicate , in other words , Only when multiple fields are combined to be exactly the same will they be de duplicated .
2.group by
SELECT t.age FROM t_user t GROUP BY t.age;3.row_number Window function The grammar format is :
row_number() over (partition by < Field name for grouping > order by < Field name used for sorting within the group >)De duplication used by the project :
select * from (select t.*,row_number() over(partition by t.children_id order by t.update_time DESC) rn from mdm_data_authority_view_info t where t.DATA_CLASS_ID = ' classification id' AND t.DATA_ROLE_ID IN ( ' role id', ' role id' )) where rn = 1; 3、 ... and 、 summary Here is a detailed explanation of mysql This is the end of the article on the three methods of data De duplication , More about mysql Data De duplication content please search the previous articles of software development network or continue to browse the following related articles. I hope you will support software development network more in the future !
边栏推荐
- 云呐|数据库监控工具,数据库监控运维工具
- VMware ESXI software 英文版安装步骤
- 网络七层结构是干啥的?看这篇文章就够了
- 面试题 05.08. 绘制直线
- Lossy transmission instance
- How to solve the worry of enterprise network with the acceleration of cloud network integration on the third anniversary of 5g licensing?
- 【C语言练习——交换两个变量的值】
- 2022.6.1-----leetcode.473
- Explain asynchronous tasks in detail: the task of function calculation triggers de duplication
- Differences between AVR and arm and common Arduino
猜你喜欢

数字化转型:如何获得组织的认可?

云呐|服务器监控的重要性,监控管理服务器有什么作用

Best practices and principles of lean product development system

Yunna intelligent operation and maintenance management system platform, visual operation and maintenance system management

Yunna RFID asset management, advantages of RFID asset management system

Development and present situation of Network Space Surveying and mapping at home and abroad

云呐|固定资产归哪个部门管理,归谁管理
mysql中的delete,drop和truncate有什么区别

Analysis on the resumption of the most serious downtime in the history of Facebook on October 4, 2021

炒作剽窃、内鬼欺诈 OpenSea上常见的NFT骗局及安全建议
随机推荐
数字化转型的七个错误认知
Event storm method of DDD modeling methodology
云呐|数据库监控工具,数据库监控运维工具
手把手教你用js实现一个虚拟机
Database day-4
软件测试工程师手把手教你如何制定测试计划
2022.5.26-----leetcode.699
Using kubekey to build kubernetes/kubesphere environment
Seven misconceptions of digital transformation
How can PostgreSQL in k8s export query results and import them to the database on the local windows machine
Wsl2 environment setup
有损传输实例
Yunna database monitoring tool, database monitoring operation and maintenance tool
HCIA-Datacom实验 IPv4编址及IPv4路由基础实验
常见的数据分析误区
Install MySQL in MySQL installer mode
记录下bilibili(b站)小火箭页面上划动画效果的实现
Who says redis can't save big keys
[leetcode weekly race record] record of the 296th weekly race
[C language practice - printing square and its deformation]