access转换为sql

时间:2017-11-06 11:09:12

标签: sql ms-access

我怎样才能将此访问语句转换为sql?

DELETE [Find duplicates for tBDEDom].* FROM [Find duplicates for tBDEDom];

1 个答案:

答案 0 :(得分:1)

CREATE TABLE #tBDEDom( Id int, Name VARCHAR(10))

insert into #tBDEDom values(1, 'abc')
insert into #tBDEDom values(2, 'mpo')
insert into #tBDEDom values(3, 'atc')
insert into #tBDEDom values(4, 'xyz')
insert into #tBDEDom values(5, 'abc')
insert into #tBDEDom values(6, 'xyz')
insert into #tBDEDom values(7, 'abc')

SELECT * FROM #tBDEDom

;with cte
AS(
    SELECT *, ROW_NUMBER()OVER(partition by Name order by Name) AS [rank] FROM #tBDEDom
)

DELETE FROM cte where [rank]>1

SELECT * FROM #tBDEDom

DROP TABLE #tBDEDom