SQL每日一题(20220614)
DELETE
FROM t1221
WHERE id = (SELECT max(id) FROM t1221 WHERE phone IN (SELECT phone FROM t1221 GROUP BY phone HAVING count(phone) >
1))
delete
from T1221
where ID not in (select a.minid from (select min(ID) as minid from T1221 group by Phone) as a)
delete
from T1221
where ID not in (select a.ID
from (select ID, Phone, row_number() over (partition by Phone order by ID ) as rk from T1221) as a
where a.rk = 1)
delete from t1221 where id in (select max(id) from t1221 GROUP BY Phone HAVING count(*) >=2)
delete
from t1221
where id in (select a.ID
from t1221 a
join t1221 b on a.phone = b.phone
where a.id >b.id)
SELECT id, phone
FROM t1221 t1
WHERE t1.`id`<=(SELECT MIN(t2.`id`)
FROM t1221 t2
WHERE t1.phone=t2.`phone`)