mysql查询

warning: 这篇文章距离上次修改已过389天,其中的内容可能已经有所变动。
-- create table student(id int,name varchar(20),cource varchar(30),grade int);
-- insert into student value(2,'王五','English',100);
-- select * from student;
-- use test;

#查询所有name字段重复值 
-- select * from student where name in (select name from student group by name having count(name)>1) order by grade desc; 

#查询所有name字段重复值中id最小的
-- select * from student where name in(select name from student group by name having count(name)>1) and id in(select min(id) from student group by name having count(name)>1);
-- SET SQL_SAFE_UPDATES = 0;
-- delete from student where name in (select t.name from(select name from student group by name having count(name)>1) t) and id in (select dt.min_id from (select min(id) as min_id from student group by name having count(name)>1) dt);
none
最后修改于:2023年04月27日 16:13

添加新评论