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.
| Author |
Topic |
|
rowter
Yak Posting Veteran
76 Posts |
Posted - 2011-12-19 : 16:25:28
|
| Hi All,We have a table with columns 'ActivityActivityTime', 'Type', vehicle_IDWe need to get reveneueTime and totalTime for each Vehicle_IDRevenueTime will be max(ActivityTime ) - min(ActivityTime ) where type <>'LN' Group by Vehicle_IDtotalTime will be max(ActivityTime ) - min(ActivityTime ) Group by Vehicle_IDNow, using a single query can we get all of this information?If not is ther any other way?thanks |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-12-19 : 17:29:01
|
You can make use of the CASE expression, like this:SELECT MAX(CASE WHEN [type] <> 'LN' THEN ActivityTime END) - MIN(CASE WHEN [type] <> 'LN' THEN ActivityTime END) AS RevenuTime, MAX(ActivityTime)-MIN(ActivityTime) AS TotalTimeFROM YourTableGROUP BY Vehicle_Id; |
 |
|
|
rowter
Yak Posting Veteran
76 Posts |
Posted - 2011-12-20 : 10:49:17
|
| Thanks a lot Sunitabeck...I found the answer here too ...http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=169307 |
 |
|
|
|
|
|