OutStockDetailID    GoodsID
1                   200703010001
1                   200703010001
1                   200703010001
2                   200703010005
2                   200703010005
3                   200703010007
3                   200703010008
这一个表里的2个字段 如果OutStockDetailID和GoodsID的内容一摸一样就不显示,如果不一样(OutStockDetailID为3的对着GoodsID有2种)就显示出来  要怎么写?

解决方案 »

  1.   

    select OutStockDetailID,GoodsID from t1 group by OutStockDetailID GoodsID having count(1)>1;
      

  2.   

    select distinct OutStockDetailID,GoodsID
      

  3.   

    select OutStockDetailID,GoodsID from t1 group by OutStockDetailID GoodsID having count(1)=1;
      

  4.   

    select OutStockDetailID,GoodsID from t1 group by OutStockDetailID GoodsID having count(1)=1;
      

  5.   

    declare @t table(OutStockDetailID int,GoodsID char(12));
    insert into @t
    select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 2,'200703010005'
    union all select 2,'200703010005'
    union all select 3,'200703010007'
    union all select 3,'200703010008'
    select * from @t;
    select OutStockDetailID,GoodsID from @t group by OutStockDetailID,GoodsID having count(1)=1;
      

  6.   

    Select Table_1.OutStockDetailID,Table_1.GoodsID
    From Table_1 join (Select OutStockDetailID,Stdev(cast(GoodsID as int)) Count
    From Table_1 Group By OutStockDetailID) temp on Table_1.OutStockDetailID=temp.OutStockDetailID and temp.Count>0
      

  7.   

    楼上的错了:
    declare @t table(OutStockDetailID int,GoodsID char(12));
    insert into @t
    select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 2,'200703010005'
    union all select 2,'200703010005'
    union all select 3,'200703010007'
    union all select 3,'200703010008'
    union all select 4,'200703010001'   --这里多加一条
    select * from @t;
    select OutStockDetailID,GoodsID from @t group by OutStockDetailID,GoodsID having count(1)=1
    如果出库单明细对应的货号group by 后只有一条,那也是正常的数据,也就没有重复不重复这种概念
    OutStockDetailID是出库明细  GoodsID是货号   现在我要查的是一条OutStockDetailID对应的好几种GoodsID的这种异常的数据 不知道讲明白了没有 THX~
      

  8.   

    这么快就有人跟贴了啊  上面的是讲sdhylj(青锋-SS) 的yiyiwyy326的貌似很复杂的语句我的意思是这个意思: 可是写的好复杂, 不知道还有没别的简单点的
    select OutStockDetailID from 
    (select OutStockDetailID, GoodsID from tbl where isnull(OutStockDetailID,'')<>'' group by OutStockDetailID, GoodsID ) a 
    group by OutStockDetailID having count(*)>1
      

  9.   

    select distinct OutStockDetailID,GoodsID
      

  10.   

    declare @t table(OutStockDetailID int,GoodsID char(12));
    insert into @t
    select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 2,'200703010005'
    union all select 2,'200703010005'
    union all select 3,'200703010007'
    union all select 3,'200703010008'
    union all select 4,'200703010001' --这里多加一条
    select * from @t;
    select OutStockDetailID from @t group by OutStockDetailID having count(1)>1;
    select OutStockDetailID,GoodsID from @t group by OutStockDetailID,GoodsID having count(1)=1 and OutStockDetailID in(select OutStockDetailID from @t group by OutStockDetailID having count(1)>1)
      

  11.   

    declare @t table(OutStockDetailID int,GoodsID char(12));
    insert into @t
    select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 2,'200703010005'
    union all select 2,'200703010005'
    union all select 3,'200703010007'
    union all select 3,'200703010008'
    select * from @t group by  OutStockDetailID, GoodsID having count(*)=1
      

  12.   

    declare @t table(OutStockDetailID int,GoodsID char(12));
    insert into @t
    select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 1,'200703010001'
    union all select 2,'200703010005'
    union all select 2,'200703010005'
    union all select 3,'200703010007'
    union all select 3,'200703010008'
    union all select 4,'200703010001'select * from @t
    where OutStockDetailID in(
    select a.OutStockDetailID from(
    select distinct OutStockDetailID,GoodsID from @t) a 
    group by a.OutStockDetailID
    having count(*) > 1)