Reputation: 1
My Boss want to know how many times each of these shipping number of days occurred. Ordered by number of days DESC. So far have :
SELECT DateDiff(shippedDate,orderDate) As '#Days', COUNT(*)
FROM datenumtest
I think I need condition, can someone help me out with this?
Upvotes: 0
Views: 24
Reputation: 5627
Calculate the DateDiff
across all records first in a data set r
, then you can do the grouping on that data set which becomes data set r1
then sort the r1
data set:
select r.NumDays, count(1) as the_count
from (
SELECT DateDiff(shippedDate,orderDate) as 'NumDays'
FROM datenumtest
) r
group by r.NumDays
order by r.NumDays desc;
Upvotes: 1