mssql2000重复视图 ,快速查询重复行视图:vip_fwjgdj

往来单位,物料,单价
viptraderid, materialid , gjdj
1          ,    2       , 3
1          ,    2       , 4
2          ,    3       , 6
3          ,    7       , 6
3          ,    8       , 9
查询当viptraerid,和materialid 相同的行
结果如下:往来单位,物料,单价
viptraderid, materialid , gjdj
1          ,    2       , 3
1          ,    2       , 4

解决方案 »

  1.   


    select *
    from tb t
    where exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 and 单价<>t.单价)
      

  2.   


    select 往来单位,物料,单价
    from tb t
    where exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 and 单价<>t.单价)
    union all
    select 往来单位,物料,单价
    from tb
    group by 往来单位,物料,单价
    having count(*) > 1
      

  3.   

    select * from tb t where
     exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 having count(1)>1)
      

  4.   


    select * from tb t where
     exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 group by 往来单位,物料 having count(1)>1)