oracle 子查询如何将外面的查询条件传进内部子查询
selectt.id,t.FLG,(casewhent.timesisnullthen(selectsfrom(selectid,APPLY_DATE,rownumsfr...
select t.id,
t.FLG,
(case
when t.times is null then
(select s
from (select id, APPLY_DATE, rownum s
from B
where id = t.A_ID
order by APPLY_DATE) f
where f.APPLY_DATE = m.APPLY_DATE)
else
t.ENQUIRY_TIMES
end) cishu,
m.APPLY_DATE
from A t, B m
where t.A_ID = m.id;
A
ID NUMBER(16)
FLG INTEGER
A_ID NUMBER(16)
TIMES VARCHAR2(40)
B
ID NUMBER(16)
APPLY_DATE DATE
这两张表的关系是 A表的A_ID是B的外键,也就是A是B的细表
解决如何将外面的查询条件传进内部子查询的问题 展开
t.FLG,
(case
when t.times is null then
(select s
from (select id, APPLY_DATE, rownum s
from B
where id = t.A_ID
order by APPLY_DATE) f
where f.APPLY_DATE = m.APPLY_DATE)
else
t.ENQUIRY_TIMES
end) cishu,
m.APPLY_DATE
from A t, B m
where t.A_ID = m.id;
A
ID NUMBER(16)
FLG INTEGER
A_ID NUMBER(16)
TIMES VARCHAR2(40)
B
ID NUMBER(16)
APPLY_DATE DATE
这两张表的关系是 A表的A_ID是B的外键,也就是A是B的细表
解决如何将外面的查询条件传进内部子查询的问题 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询