我的表如下:
Balance Value 1 Value2 Date Daily Change (Expected) 8 8,648,668.60 12,620,390.51 3/27/2018 -1 7 3,087,707.30 3,494,174.70 3/28/2018 -1 6 3,039,443.51 2,345,356.15 3/29/2018 -1
如何设置查询的格式,以使“每日更改”列与前一天的余额和前一天的余额之差?
让我们将我的表称为“表”
为了
3/27/2018 - 3/26/2018 3/28/2018 - 3/27/2018 3/29/2018 - 3/28/2018
我用以下内容回答了这个问题:
选择t1。*,t1.balance-t2.balance从TestData t1的Daily_Change到LE2 JOINT TestData t2在t2.report_date = DATE_SUB(t1.report_date,INTERVAL 1 DAY)和t1.account = t2.account ORDER BY t1.report_date,t1 。帐户