type
Post
status
Published
date
slug
summary
tags
Mysql
category
技术分享
icon
password
Property
Feb 23, 2023 09:33 AM
Language
找出重复数据并且保留最小ID数据 SELECT * FROM student WHERE id NOT IN ( SELECT t.id FROM ( SELECT MIN(id) AS id FROM student GROUP BY `name` ) t )
还有一种情况选取一个字段的最大值或者最小值
Column1 Column2 Column3 Column4 Column5 1 B X X X 2 A Y Y Y 3 E Z Z Z 4 B X X X 5 C Y Y Y 6 E Z Z Z 7 C X X X 8 B Y Y Y 9 B Z Z Z
select t.* from t where t.columnA = (select max(t2.columnA) from t t2 where t2.columnB = t.columnB); If you actually want to remove them, then one method is: delete from t where t.columnA < (select max(t2.columnA) from t t2 where t2.columnB = t.columnB);
select * FROM vol_du t1, vol_du t2 WHERE t1.duration > t2.duration AND t1.idnumber = t2.idnumber SELECT memberid, idnumber, MAX(duration) FROM vol_du GROUP BY idnumber;
- Author:Qi
- URL:https://blog.ltq.im/article/052df2e7-cda6-4227-a8b7-e7d45f7a5560
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts