【发布时间】:2019-02-06 19:17:15
【问题描述】:
我有一张表格,每行都有不同客户的发票。 我想通过使用 SQL(或 SQL HANA)获得不仅是同一个月和客户的所有发票的总金额,而且还要在另一列中获得上个月的总金额。
让:
Customer, Invoice Date(YearMonth), Amount
1, 201812, 12
1, 201811, 10
1, 201811, 15
1, 201811, 20
1, 201808, 12
1, 201807, 66
1, 201804, 12
1, 201801, 12
2, ...
...
=>
Customer, YearMonth Invoices, Total Month, Total Previous Month(YM -1 )
1, 201812, 12, 45
1, 201811, 45, 0
1, 201808, 12, 66
1, 201807, 66, 0
1, 201804, 12, 0
1, 201801, 12, 0
2, ..
注意:我也有确切的发票日期,而不仅仅是年月
【问题讨论】: