SQL SERVER可以这么写,其他的数据库可能不行。
delect a 
from table1 a 
where exists(
select * from table1 b 
where a.price=b.price 
and a.id>b.id
)

解决方案 »

  1.   

    如果其他数据库不行,可以试一下,不敢保证可以:
    delect from table1 as a 
    where exists(
    select * from table1 as b 
    where a.price=b.price 
    and a.id>b.id
    )
      

  2.   

    delete a from tablename  a,(select max(id) as id,price from tablename b) where a.price=b.price and a.id>b.id
      

  3.   

    exist太慢了,
    还不如将不重复记录倒入临时表中:
    insert into temp_table select min(id) as id, price from table1 group by price;
    然后倒回来:
    drop table table1;
    rename table temp_table to table1;
      

  4.   

    谢谢!
    我这样写好像也可以.
    delect from table1 
    where exists(
    select * from table1 as b 
    where table1.price=b.price 
    and table1.id>b.id
    )
    呵呵,结果好像也正确,只是可读性太差。