Calculate percent increase/decrease from previous row value

后端 未结 5 1079
再見小時候
再見小時候 2021-01-06 16:57

I have a table that looks something like this:

|date_start  | date_end    |amount | 
+------------+-------------+-------+
|2015-02-23  | 2015-03-01  |50              


        
5条回答
  •  北恋
    北恋 (楼主)
    2021-01-06 17:37

    Try this:

     SELECT t.*,
     amount - (SELECT amount FROM transactions prev WHERE prev.date_end     < t.date_start ORDER BY date_start DESC LIMIT 1) AS changes
     FROM   transactions t
    

提交回复
热议问题