sql刪除重複資料

2021-06-07 04:20:52 字數 614 閱讀 5042

1)建立表

create table [dbo].[test] (

[id] [numeric](18, 0) identity (1, 1) not null primary key,

[name] [varchar] (200) collate chinese_prc_ci_as null ,

[remark] [varchar] (1024) collate chinese_prc_ci_as null ,

[step] [int] null

) go

2)插入資料

insert into test values('d','d',3)

insert into test values('d','d',3)

insert into test values('dk','dk',3)

insert into test values('dk','dk',3)

3)根據step刪除,如果name和remark一樣,就刪除小的記錄

delete from test where id  not in (select max(id) from test group by name,remark,step) and step=3

sql刪除重複資料

sql刪除重複資料 如果該錶需要刪除重複的記錄 重覆記錄保留1條 可以按以下方法刪除 select distinct into tmp from tablename drop table tablename select into tablename from tmp drop table tmp ...

SQL刪除重複資料

這個應用場景也不多說了 with c as select orderid,row number over partition by orderid order by select null as nfrom sales.myorders delete from c where n 1 利用row n...

sql 刪除重複資料語句

現在有表資料如下圖1 需要刪除表中除id外重複的資料,實現如下圖所示效果圖2 篩選根據name,value分組後id最大的非重複資料 select max id from deleterepeat group by name value 下面是實現效果圖2 的語句 delete from delet...