日期:2014-05-18 浏览次数:20498 次
select * from tb t where price=(select min(price) from tb where cardid=t.cardid)
------解决方案--------------------
DELETE a FROM 你的表名 a WHERE EXISTS ( SELECT TOP 1 * FROM 你的表名 WHERE cardId = a.cardId AND price > a.price )
------解决方案--------------------
create table dashanliu (cardId char(5), price decimal(3,1), name char(5)) insert into dashanliu select '001', 0.9, 'aaa' union all select '002', 1.5, 'bbb' union all select '001', 0.5, 'ccc' union all select '003', 1.2, 'ddd' select cardId,price,name from (select row_number() over(partition by cardId order by price) rn, cardId,price,name from dashanliu) t where t.rn=1 cardId price name ------ --------------------------------------- ----- 001 0.5 ccc 002 1.5 bbb 003 1.2 ddd