select t2.d_year, t2.d_month, Round(100.0 * t2.diff / t2....

0

Please login or register to vote for this query.

(click on this box to dismiss)

Drupal Answers

Q&A for Drupal developers and administrators

select t2.d_year, t2.d_month, Round(100.0 * t2.diff / t2.prev_month, 2) as Percentage

from

(
  select t1.d_year, t1.d_month, count(t1.id) as d_count,
  LAG(count(t1.id)) OVER (ORDER BY t1.d_year, t1.d_month) AS prev_month, 
  count(t1.id) - (LAG(count(t1.id)) OVER (ORDER BY t1.d_year, t1.d_month)) as diff
  from
  (
    select id, YEAR(CreationDate) as d_year, MONTH(CreationDate) as d_month
    from posts
  ) t1
  group by t1.d_month, t1.d_year
) t2
where Round(100.0 * t2.diff / t2.prev_month,2) < 0
order by t2.d_year, t2.d_month

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results