2021年3月7日星期日

How to calculate the difference between current row and the last row of last month?

        update_time         |   net_value   ----------------------------+---------------------------   2021-03-03 00:33:00.13055  |    0.6   2021-03-02 14:23:18.173233 |    0.5   2021-03-01 01:31:00.146775 |    0.3   2021-02-28 00:33:00.13055  |    0.2    

I have a postgres table net_value as above, one row one day.

How can I calculate the difference between current row and the last row of last month? Look like the output as below:

        update_time         |   monthly_diff   ----------------------------+---------------------------   2021-03-03 00:33:00.13055  |    0.4 // 0.6 - 0.2   2021-03-02 14:23:18.173233 |    0.3 // 0.5 - 0.2   2021-03-01 01:31:00.146775 |    0.1 // 0.3 - 0.2   2021-02-28 00:33:00.13055  |    0.2 // 0.2 - 0  

Thanks!

https://stackoverflow.com/questions/66523670/how-to-calculate-the-difference-between-current-row-and-the-last-row-of-last-mon March 08, 2021 at 10:37AM

没有评论:

发表评论