select * from 表 aa where not exists(select 1 from 表 bb where aa.item=bb.item and aa.id>bb.id)

解决方案 »

  1.   

    declare @status char(1)
    set @status='R'
    select * from 表 where status=@status union all select * from 表 where item not in (select item from 表 where status=@status)
      

  2.   

    declare @status char(1)
    set @status='R'
    select * from 表 where status=@status union all select * from 表 where item not in (select item from 表 where status=@status)
      

  3.   

    select * from yourtable A
    where exists (select * from yourtable 
                   where item = A.item and status = A.status and status = 'R')
    or no exists (select * from yourtable where item = A.item and status = 'R')