日期:2014-05-18 浏览次数:20774 次
--随便写个 Select * from tb t where not exists(select 1 from tb where [Item]=t.[Item] and [Type]=1) and not exists(select 1 from tb where [Item]=t.[Item] and [Type]=2) and not exists(select 1 from tb where [Item]=t.[Item] and [Type]=3)
------解决方案--------------------
if object_id('[tb]') is not null drop table [tb] go create table [tb]([Item] varchar(3),[Type] int) insert [tb] select 'it1',1 union all select 'it1',5 union all select 'it1',6 union all select 'it2',2 union all select 'it2',3 union all select 'it3',4 union all select 'it3',5 union all select 'it4',8 select * from [tb] t where not exists(select 1 from tb where item=t.item and type in(1,2,3)) /* Item Type ---- ----------- it3 4 it3 5 it4 8 (3 行受影响) */