group by

Last Post 22 Apr 2005 04:16 PM by nosepicker. 2 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
trans53
New Member
New Member

--
22 Apr 2005 02:23 PM
Need your help please:

i have this record set :


account card id active date removed date date diff
11147 20826 2005-04-02 16:58:41.000 2005-04-20 16:21:40.000 18
11148 18264 2005-04-10 15:17:19.000 2005-04-20 15:16:08.180 10


Now i need to calculate the total count for the cards that has datediff < 10 days, >= 10 and < 30 days


How can this be done in this case?

Thanks
nosepicker
New Member
New Member

--
22 Apr 2005 04:16 PM
I think this is what you need (I added a [>= 30 days] category just for the heck of it):

SELECT
SUM(ISNULL(CASE WHEN date_diff < 10 THEN 1 END, 0)) AS [< 10 days],
SUM(ISNULL(CASE WHEN date_diff >= 10 AND date_diff < 30 THEN 1 END, 0)) AS [>= 10 & < 30 days],
SUM(ISNULL(CASE WHEN date_diff >= 30 THEN 1 END, 0)) AS [>= 30 days]
FROM YourTable


trans53
New Member
New Member

--
25 Apr 2005 07:44 AM
Thanks a lot
You are not authorized to post a reply.

Acceptable Use Policy