-- 设置可唯一识别的字段(此处是lmt) update update_t_datameas set lmt = t.lmt from update_t_datameas s, ( SELECT stcd, POINTID, dt, v1, v2, v3, r1, r2, r3, DATEADD(second, ABS(CHECKSUM(NEWID())) % DATEDIFF(second,'00:00','23:59'), CONVERT(char(20),dt,20) ) as lmt from update_t_datameas s ) t where s.stcd = t.stcd and s.POINTID = t.POINTID and s.dt = t.dt
-- 设置保留lmt时间最大的一条数据 DELETEfrom update_t_datameas where stcd in (SELECT stcd from update_t_datameas GROUPBY stcd, POINTID, dt HAVINGcount(*)>1) and dt in (SELECT dt from update_t_datameas GROUPBY stcd, POINTID, dt HAVINGcount(*)>1) and POINTID in (SELECT POINTID from update_t_datameas GROUPBY stcd, POINTID, dt HAVINGcount(*)>1) and lmt notin (SELECTmax(lmt) from update_t_datameas GROUPBY stcd, POINTID, dt HAVINGcount(*)>1)