oracle连接消除重复项,oracle 多表连接时消除重复

with A as (select aa.eqid,aa.usedate, aa.field,aa.track,m.name,ROW_NUMBER()OVER(PARTITION BY eqid ORDER BY usedate )RN from r_device_one aa left join  b_model m on aa.modelid = m.id where aa.eqid= '1'),

B as (select aa.eqid, tt.bh, tt.issuedtime, tt.operator, tt.issuedtypeid,dd.name xlname,ff.name, ROW_NUMBER()OVER(PARTITION BY aa.eqid ORDER BY tt.issuedtime )RN

from R_DEVICE_one aa

left JOIN t_WW tt

on aa.eqid between tt.eqidstart and tt.eqidend

join B_BASICDATA dd

on tt.xlstateid = dd.id

and dd.type = '线路状态'

left join T_repair_TWO cc on aa.eqid = cc.eqid and tt.bh = cc.inspectionid

left join  B_BASICDATA ff on cc.operate = ff.id and ff.type = '故障类型'

where aa.eqid = '1'),

C as (select rr.eqid,rr.bh, rr.issuedtime,rr.operator,rr.confirmer ,rr.explain,dd.name,ROW_NUMBER()OVER(PARTITION BY eqid ORDER BY issuedtime )RN from t_repair_TWO rr left join  B_BASICDATA dd

on rr.operate = dd.id and dd.type = '故障类型' where rr.eqid = '1')

SELECT AA.*,BB.bh B_BH,BB.issuedtime B_issuedtime, BB.operator B_operator, BB.issuedtypeid B_issuedtypeid,BB.xlname B_xlname, BB.name B_name,CC.BH c_BH,CC.issuedtime c_issuedtime,CC.operator c_operator,CC.explain,CC.name C_NAME ,CC.confirmer FROM A AA

full JOIN B BB ON AA.eqid=BB.eqid and AA.RN = BB.RN

full JOIN C CC ON BB.eqid=CC.eqid and BB.RN = CC.RN

本文最关键的在于分组排序利用RN值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值