Untitled

From Max, 4 Months ago, written in Plain Text, viewed 60 times. This paste will perish in 1 Second.
URL http://codebin.org/view/9dd6b968 Embed
Download Paste or View Raw
  1. WITH tmp AS
  2. (
  3. SELECT  DISTINCT
  4. DATE_TRUNC('month', created_at) :: date AS dt,
  5. SUM(costs) OVER(PARTITION BY DATE_TRUNC('month', created_at) :: date) AS month_cost
  6. FROM tools_shop.costs
  7. ORDER BY DATE_TRUNC('month', created_at) :: date
  8. )
  9.  
  10. SELECT dt,
  11. month_cost,
  12. month_cost - LAG(month_cost, 1, month_cost) OVER(ORDER BY dt) AS delta
  13. FROM tmp

Reply to "Untitled"

Here you can reply to the paste above