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
列
往来单位,物料,单价
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
select *
from tb t
where exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 and 单价<>t.单价)
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
exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 having count(1)>1)
select * from tb t where
exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 group by 往来单位,物料 having count(1)>1)