Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Group By

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-04 : 11:29:03
Rob writes "I have a situation where i am calculating the difference between two dates. The table looks like this. (TravelDate, BookDate,Cost)

So far my string looks like..."Select Cost,
dateDiff(d, bookdate,traveldate) as dateDifference from data"

I want to eventually sum the total cost for each group of differences. For instance, sql server may return

0 - $50
0 - $23
0 - $5
1 - $6
2 - $34
2 - $66
5 - $0

so the sum cost for a date difference of 0 would be $78, for a date difference of 1 day, $6.. etc.

I can't group by the alias, so is there any way to get the sum costs for the groups of days? Thankks for your time-"

nricardo
Starting Member

17 Posts

Posted - 2002-01-04 : 11:35:59
group by dateDiff(d, bookdate,traveldate)

Don't forget to SUM(cost)


Edited by - nricardo on 01/04/2002 11:37:18
Go to Top of Page
   

- Advertisement -