create TABLE [dbo].[products1]
(
[rowid] [int] primary key IDENTITY(1,1) NOT NULL,
[name] [nchar](10) NULL,
[price] [int] NULL
)
insert INTO Products VALUES('蘋果', 50);
insert INTO Products VALUES('橘子', 100);
insert INTO Products VALUES('橘子', 100);
insert INTO Products VALUES('橘子', 100);
insert INTO Products VALUES('香蕉', 80);
insert INTO Products VALUES('香蕉', 80);
delete products from products as p1
where p1.rowid<
(
select MAX(p2.rowid) from products p2
where p1.name=p2.name and p1.price=p2.price
)
--結(jié)果:
-- rowid name price
-- 1 蘋果 50
-- 4 橘子 100
-- 6 香蕉 80