这里的人都这么势利呢?不见分就不回答,还是我来。
delete from newCar a
    left join (select Licence_ID,max(CreateDate) from newCar where b.Licence_ID=null group by Licence_ID having count(*)>1) b on a.Licence_ID=b.Licence_ID and a.CreateDate=b.CreateDate
where a.Budget_ID != null and b.Licence_ID=null

解决方案 »

  1.   

    修改一下:
    delete newCar from newCar a
        left join (select Licence_ID,max(CreateDate) from newCar where b.Licence_ID=null group by Licence_ID having count(*)>1) b on a.Licence_ID=b.Licence_ID and a.CreateDate=b.CreateDate
    where a.Budget_ID not is null and b.Licence_ID is null
      

  2.   

    第三版:
    delete newCar from newCar a
        left join (select Licence_ID,max(CreateDate) from newCar where b.Licence_ID not is null group by Licence_ID having count(*)>1) b on a.Licence_ID=b.Licence_ID and a.CreateDate=b.CreateDate
    where a.Budget_ID not is null and b.Licence_ID is nullnull不能用'='或者'!='进行判断。
      

  3.   

    试着帮你再修改一下,算是终结版了,呵呵。
    delete newCar from newCar a
        left join (select Licence_ID,max(CreateDate) from newCar where b.Licence_ID not is null group by Licence_ID having count(*)>1) b on a.Licence_ID=b.Licence_ID and a.CreateDate=b.CreateDate
    where a.Budget_ID not is null and b.Licence_ID is null and a.Licence_ID in(select Licence_ID from newCar group by Licence_ID having count(*)>1)
      

  4.   

    create table gggs(Licence_ID int,CreateDate smalldatetime,Budget_ID int)
    insert gggs select 1,'2006-06-05',234
    insert gggs select  1,'2006-09-02',32
    insert gggs  select 2,'2006-09-07',432
    insert gggs  select 2,'2006-09-14',nulldelete from gggs where 
    exists(select 1 from gggs a where a.Licence_ID=gggs.Licence_ID and a.CreateDate>gggs.CreateDate and Budget_ID is not null)  or Budget_ID is null
    select * from gggs