oracle多表查询,表结构相同,但没有相关联
selectLCN,PID,TF,BAL,TIM,TTfromKQY_KMBBwherePID='20020807'结果有1744条记录selectLCN,substr(...
select LCN,PID,TF,BAL,TIM,TT from KQY_KMBB where PID='20020807'
结果有1744条记录
select LCN,substr(PID,5),TF,BAL,TIM,TT from KQY_KCBB where substr(PID,5)='20020807'
结果有88条记录
需求是想直接显示1832条记录,用表关联的话
select (case when A.LCN is not null then A.LCN else B.LCN end) as LCN,
(case when A.PID is not null then A.PID else substr(B.PID,5) end) as PID,
(case when A.TF is not null then A.TF else B.TF end) as TF,
(case when A.BAL is not null then A.BAL else B.BAL end) as BAL,
(case when A.TIM is not null then A.TIM else B.TIM end) as TIM,
(case when A.TT is not null then A.TT else B.TT end) as TT
from KQY_KMBB a join KQY_KCBB b on substr(B.PID,5)='20020807' and A.PID=substr(B.PID,5)
上面SQL产生笛卡尔积了,怎么消除?这两个表内没有只有PID相同的 展开
结果有1744条记录
select LCN,substr(PID,5),TF,BAL,TIM,TT from KQY_KCBB where substr(PID,5)='20020807'
结果有88条记录
需求是想直接显示1832条记录,用表关联的话
select (case when A.LCN is not null then A.LCN else B.LCN end) as LCN,
(case when A.PID is not null then A.PID else substr(B.PID,5) end) as PID,
(case when A.TF is not null then A.TF else B.TF end) as TF,
(case when A.BAL is not null then A.BAL else B.BAL end) as BAL,
(case when A.TIM is not null then A.TIM else B.TIM end) as TIM,
(case when A.TT is not null then A.TT else B.TT end) as TT
from KQY_KMBB a join KQY_KCBB b on substr(B.PID,5)='20020807' and A.PID=substr(B.PID,5)
上面SQL产生笛卡尔积了,怎么消除?这两个表内没有只有PID相同的 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询