我通过一串SELECT语句得到一下结果:
     
    订单号      行号       商品代码         数量         单价         标识
      123       001        14021        200         20.12       1
     123       001        14021        200         20.12       4
     215       001        14021        200         20.00       1
     215       002        14021        500         10.18       1
     215       003        14021        212         20.12       1
     111       001        14021        200         20.12       4
     111       001        14021        200         20.12       1
     200       001        14021        200         20.12       4   
     200       001        14021        200         20.12       1我现在的目的是把 行号 和 订单号相同的记录中标识是 4 的记录删除掉,保留其他的记录

解决方案 »

  1.   

    delete from table where 标识=4
      

  2.   

    delete t
    from tab t
    where 标识=4
    and exists (
    select 1 from tab
    where 订单号=t.订单号 and 行号=t.行号
    and 标识<>4
    )
      

  3.   

    declare @tmp1 table(id int IDENTITY(1,1),订单号 varchar(10),行号 varchar(10),商品代码 varchar(10),数量 int,单价 numeric(10, 2),标识 int)insert into @tmp1 select -- 通过一串SELECT语句得到一下结果delete from @tmp1 where id in (select id from @tmp1 where 标识=4 group by 行号,订单号)select * from @tmp1