SQL-查询重复语句(多字段)

2019-02-19  本文已影响3人  malgee

多字段查询重复的语句
其中
a.historyHumi, a.historyTemp, a.historyTime, a.historyIndex
是需要使用的字段

SELECT*FROM MGWeatherglassValueTable a
WHERE 
(SELECT count(1) FROM MGWeatherglassValueTable WHERE a.historyTime=historyTime AND a.historyIndex=historyIndex AND a.historyHumi=historyHumi AND a.historyTemp=historyTemp)> 1
删除重复的数据只保存一条重复的数据
delete from MGWeatherglassValueTable 
where keyId not 
in ( select * from(select keyId from MGWeatherglassValueTable group by historyHumi,historyTemp, historyTime, historyIndex) b);
上一篇下一篇

猜你喜欢

热点阅读