sql 查询表中姓名和联系电话均重复的数据,并将重复的数据只留一条,其他重复数据更新状态为1,这个sql语句怎么写?
//1.查询满足条件的大于1条的数据
select *frmo table where count(name)>1 and count(tel)>1;
//2.通过row_number() over对上面数据进行重新排序,得到一个从1开始的序号Rid
//3.update Rid>1的数据 修改状态为1
?????会distinct
update table c, (SELECT name,phone,min(id) as a FROM table GROUP BY name,phone ) t
set c.zt='1'
WHERE c.name = t.name AND c.phone = t.phone
and c.id <> t.a
UPDATE 表1 set 状态 = 1 where ID in(
select max(ghk_ID) from 表1 as h1
where (select COUNT(*) from 表1 as h2 where h2.重复字段1=h1.重复字段1 and h2.重复字段2=h1.重复字段2 )>1
group by 重复字段1,重复字段2)