mssql2000重复视图

sufull88 2012-08-16 09:59:47
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

...全文
159 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
AcHerat 2012-08-16
  • 打赏
  • 举报
回复

select * from tb t where
exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 group by 往来单位,物料 having count(1)>1)
正牌风哥 2012-08-16
  • 打赏
  • 举报
回复
select * from tb t where
exists (select 1 from tb where 往来单位=t.往来单位 and 物料=t.物料 having count(1)>1)
sufull88 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
SQL code

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

……
[/Quote]

好的,谢谢!有没有更高效率的代码处理呢?
AcHerat 2012-08-16
  • 打赏
  • 举报
回复

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
sufull88 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
SQL code

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

谢谢回复,但是也有可能 单价=t.单价 这种情况出现
AcHerat 2012-08-16
  • 打赏
  • 举报
回复

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

22,298

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧