【发布时间】:2014-04-28 14:48:28
【问题描述】:
我想要做的是编写一个查询,提供以下输出:
帐号的日期值是一个计算字段,它使用当前数据库中的信息计算一个数字。然后对于第 +1 天,我需要从日期值开始计算。但是我怎样才能传递这个值,以便我可以在第 +1 天使用它来计算呢?我怎样才能做到这一点?他们不喜欢在我的工作场所使用 pl sql,所以这是最坏的情况。
目前我只写了一天的查询来获取所有 16 个帐户的信息:
select OBforeachaccount.accountnumber accountnumbers, (OBforeachaccount.OB - NVL(IDforeachaccount.sumamounts,0) - NVL(paymentsforeachaccount.sumpayments,0)) as day1, day1+5 as day2
from
--ophalen van CB day -1
(select account_id accountnumber,cal_date,cb_amount_default OB from fillinggaps g, dim_date d
where g.balance_date = d.cal_date and
d.cal_date = TO_CHAR(sysdate -1,'DD/MM/YYYY')
order by account_id, cal_date) OBforeachaccount,
(select a.id accountnumber, cal_date, sum(AMOUNT_USD) sumamounts
from fact_id_transaction i, dim_date d, dim_account a
where i.value_date_id = d.id and
i.account_id = a.id and
d.cal_date = TO_CHAR(sysdate -1,'DD/MM/YYYY')
--future: add filter based on the account number
group by a.id, cal_date
order by a.id,cal_date) IDforeachaccount,
(select ordering_account_id accountnumber,cal_date, sum(instructed_amount_default) sumpayments
from fact_payment p, dim_date d
where
p.value_date_id = d.id and
d.cal_date = TO_CHAR(sysdate -1,'DD/MM/YYYY')
group by ordering_account_id, cal_date
order by ordering_account_id, cal_date) paymentsforeachaccount
where
OBforeachaccount.accountnumber = IDforeachaccount.accountnumber(+) and
OBforeachaccount.accountnumber = paymentsforeachaccount.accountnumber(+)
谢谢大家的建议
【问题讨论】:
-
您使用的是哪个版本的 Oracle? 11gR2?
-
我使用的是 11G 版本
标签: sql oracle subquery oracle-sqldeveloper correlated-subquery