comment ids over time


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

declare @endDate date;
select @endDate = max(creationdate) from comments;
declare @daysPerBin int= ##daysPerBin?7##;

with did as
(select row_number() over (order by d asc) as row, d, min(id) as id from
(select dateadd(day,
  @daysPerBin * (datediff(day, @endDate, creationdate)/@daysPerBin),
  @endDate) as d, id
from comments) as x
group by d)

select cur.d, - as deltaId
from did cur
join did previous
on cur.row = previous.row + 1
order by cur.d asc

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results