我正在尝试根据日期使用 oracle SQL 多次选择相同的数据。
例如,此刻我编写了这个 SQL 查询来计算我在当前日期的余额:
select to_char(sysdate, 'DD-MM-YYYY') date,
(
select (
select NVL(sum(bedrag), 0) bedrag
from transactie
where rekening_naar_id = r.id
and datum <= sysdate
and actief = 1
)
-
(
select NVL(sum(bedrag), 0) bedrag
from transactie
where rekening_van_id = r.id
and datum <= sysdate
and actief = 1
)
from dual
)
as balance
from rekening r
where r.id = 2;
我想知道是否可以在单个 SQL 查询中多次循环遍历相同的数据并选择多行,每次只需将日期增加 1 天?余额根据图表中显示的日期而变化。
我不能对这个查询使用 PL/SQL,因为我需要将数据填充到 Oracle Apex 图表中,并且没有使用 PL/SQL 生成图表的选项。只允许返回有效 SQL 查询的有效 SQL 查询或 PL/SQL 代码。