sql刪除表中某個欄位的重複資料,取較大者

2021-09-07 18:22:28 字數 369 閱讀 5483

delete from ac31

where aac310 not in

( select max310 from

( select max(aac310) as max310

from ac31

group by aac001

)b);

解析:由內而外看,最裡層select語句以aac001欄位分組,從ac31表中篩選資料,取aac310列值較大者,取別名max310。

中間層select語句,篩選出max310。

最外層select語句,將ac31表中aac310欄位不在max310中的行刪掉,即刪除aac310中較小的值。

參考文獻:

treeview 讀取SQL表中某個字段

var index integer strfzyw string treenode ttreenode begin strfzyw main fm.rzstatuspane2.caption if rzpagecontrol1.activepage tabsheet2 then begin with...

sql 刪除重複或查詢某個字段相同最新記錄

例如tablea表中有如3個字段 id typeid name adddate,記錄特徵是 當有多個記錄有相同typeid值時。1 每個typeid值保留一條最新的記錄,即刪除同乙個typeid的非最新記錄 delete from tablea a where 1 1 and exists sele...

MYSQL刪除某個字段多餘重覆記錄

sells表資訊 create table sells id int 11 not null auto increment,唯一id name varchar 50 not null,姓名 phone varchar 10 not null,project varchar 50 not null,專...