第一步:查詢重覆記錄
select * from tablename
where repeatfiled in (
select repeatfiled
from tablename
group by repeatfiled
h**ing count(repeatfiled) > 1
)這一段邏輯很簡單,就是把重複條數大於1的全部都搞出來就行了。
第二步:刪除重覆記錄,只保留一條
select * from tablename
where repeatfiled in (
select repeatfiled
from tablename
group by repeatfiled
h**ing count(repeatfiled) > 1
andid not in (
select min(id)
from tablename
group repeatfiled
h**ing count(repeatfiled) > 1 ))
在上一步的基礎上繼續過濾,那就把最小值留下就行了,大功告成!
SQL去除某欄位重覆記錄
sql去除某欄位重覆記錄 原理 對需要去重覆記錄的字段按組排序,然後取其中一條記錄。在總查詢語句中使用in語法過濾 去掉重覆記錄 select from company where comid in select max comid from company group by companyname...
SQL去除某欄位重覆記錄
原理 對需要去重覆記錄的字段按組排序,然後取其中一條記錄。在總查詢語句中使用in語法過濾 去掉重覆記錄 select from company where comid in select max comid from company group by companyname 得到重覆記錄數 sele...
SQL去除某欄位重覆記錄
原理 對需要去重覆記錄的字段按組排序,然後取其中一條記錄。在總查詢語句中使用in語法過濾 去掉重覆記錄 select from company where comid in select max comid from company group by companyname 得到重覆記錄數 sele...