delete
FROM App_Ponderation e2
WHERE (ID <
          (SELECT MAX(e1.id)
         FROM app_ponderation e1
         WHERE e1.idcode = e2.idcode))请教大家帮我看看上面的SQL语句那里出错,本人是想把有不同ID号而有相同的IDCODE的数据笧徐

解决方案 »

  1.   

    create table App_Ponderation
    (
    id int,
    idcode varchar(2)
    )
    insert into App_Ponderation
    select 1,'a' union all
    select 2,'b' union all
    select 3,'c' union all
    select 4,'a' union all
    select 5,'c'
    select * from App_Ponderationdelete from App_Ponderation
    where id not in(select max(id) from App_Ponderation group by idcode)
    select * from App_Ponderation
      

  2.   

    delete e2
    FROM App_Ponderation e2
    WHERE (ID <
              (SELECT MAX(e1.id)
             FROM app_ponderation e1
             WHERE e1.idcode = e2.idcode))