Untitled

From Beefy Cat, 4 Months ago, written in SQL, viewed 68 times.
URL http://codebin.org/view/79d7248a Embed
Download Paste or View Raw
  1. WITH ms AS
  2.     (SELECT DISTINCT DATE_TRUNC('month', created_at)::DATE AS mnth
  3.         , SUM(costs) OVER (PARTITION BY DATE_TRUNC('month', created_at)::DATE
  4.                           ORDER BY DATE_TRUNC('month', created_at)::DATE) AS sum_month --numeric
  5.     FROM tools_shop.costs
  6.     ORDER BY mnth)
  7.    
  8. SELECT mnth
  9.     , sum_month
  10.     --, LAG(sum_month, 1, 0) OVER () -- так не работает? ошибка sum_month: function lag(numeric, integer, integer) does not exist
  11.     , LAG(CAST(sum_month AS INT), 1, 0) OVER ()
  12.     , sum_month - LAG(CAST(sum_month AS INT), 1, 0) OVER () AS month_diff
  13.  
  14. FROM ms
  15. ORDER BY mnth

Reply to "Untitled"

Here you can reply to the paste above