[thelist] SQL query to create aging buckets

Joel D Canfield joel at spinhead.com
Wed Dec 17 15:28:34 CST 2003


I'm trying to figure out the SQL (on MSSQL) to group results after
rounding. Here's the query I'm running:
 
  select datediff(d,duedate,getdate()) from tasks 
 
against data which looks approximately like this (not necessarily the
real data):
 
  2003-12-05 14:57:19.000
  2003-12-05 17:00:09.000
  2003-12-05 17:04:24.000
  2003-12-06 09:52:28.000
  2003-12-06 16:01:30.000
  2003-12-08 09:16:16.000
  2003-12-08 11:28:43.000
  2003-12-08 12:39:00.000
  2003-12-08 12:47:11.000

which returns a list like this:
 
  12
  12
  12
  11
  11
  9
  9
  9
  9

I want to see a count of each number, thus:
 
  3  12
  2  11
  4   9
 
Seems like it should be possible, but it's not coming to me in a vision
or anything
 
Thanks
 
joel  


More information about the thelist mailing list