我有一张桌子如下
===========================
+---------+----------+--------
ACC_NUM DATE BALANCE
+---------+----------+--------
A101 01-01-19 120
+---------+----------+--------
A101 02-01-19 100
+---------+----------+--------
A101 03-01-19 90
+---------+----------+--------
我想要输出如下:
==========================
+---------+----------+--------,--------------,
ACC_NUM . DATE . BALANCE' PEV_DATE_BAL '
+---------+----------+--------'--------------'
A101 01-01-19 120 '
---------------------------------------------'
A101 02-01-19 100 120 '
---------------------------------------------'
A101 03-01-19 90 100 '
----------------------------------------------
什么查询可以输出如下?
答案 0 :(得分:4)
使用LAG功能:
SELECT ACC_NUM
, DATE_c
, BALANCE
, LAG(BALANCE) OVER (
ORDER BY DATE_c
) PEV_DATE_BAL
FROM testTable;
这里是DEMO