现有表table1,
数据如下
product   order
  p1        o1
  p2        o1
  p4        o2
  p5        o2
  p6        o3
  p7        o3
  p7        o4
 
当出现product对应多个order时求查出produt及order~

解决方案 »

  1.   

    SELECT * FROM TB T WHERE EXISTS(SELECT 1 FROM product=T.product AND [order]<>T.[order])
      

  2.   

    题目没看懂,你的product 和order是table1的两个列还是2个表,最重要的是没明白 你 最终要的是什么数据
      

  3.   


    select * 
    from tb t 
    where exists(select 1 from product=t.product and [order]<>t.[order])
      

  4.   


    select * 
    from tb t 
    where (select count(*) from tb where product = t.product) > 1
      

  5.   

     
      select * from table1 T 
      where product in (
            select Product from Table1 
            group by product
            having count(order)>1 )
      

  6.   

    select *  from tb t  where exists(select 1 from product=t.product and [order]<>t.[order])
      

  7.   


    create table #table1(product nvarchar(5), [order] nvarchar(5))
    insert  #table1
      select 'p1','o1' union all
      select 'p2','o1' union all
      select 'p4','o2' union all
      select 'p5','o2' union all
      select 'p6','o3' union all
      select 'p7','o3' union all
      select 'p7','o4'select * from #table1 as t1 where
    exists(select 1 from #table1 as t2 where t1.product=t2.product and t1.[order]<>t2.[order])
      

  8.   


    select * from table1 where product in(select product from table1 group by product having count(1)>1)