Column that is the difference between values of same column perday

后端 未结 2 1786
孤城傲影
孤城傲影 2021-01-29 06:46

My table is as follows:

Balance          Value 1        Value2          Date        Daily Change (Expected)  
8                8,648,668.60   12,620,390.51   3/2         


        
2条回答
  •  灰色年华
    2021-01-29 07:16

    You can use a left join:

    select t.*,
           (t.balance - tprev.balance) as daily_change
    from `table` t left join
         `table` tprev
         on t.date = tprev.date  + interval 1 day;
    

提交回复
热议问题