February 21, 2006 at 11:00 am
I have a table of user activities look like below:
Name | Login | Logout |
A | 7:45 | 14:20 |
A | 14:38 | 17:55 |
B | 10:25 | 15:10 |
B | 15:20 | 17:22 |
B | 17:25 | 18:00 |
How do I get a report with expected output as:
Name | Duration |
A | 9:52 |
B | 7:22 |
Duration is total of time a user spent between each login and logout. Thanks.
p.s the login and logout time are converted from a date time column. I still have the time in original format.
February 21, 2006 at 11:14 am
select [name],sum(datediff(n,logout,login)) /*total amount of minutes*/
from mytable
group by [name]
order by [name]
You can format the amount of minutes in your report or with a userdefined function.
February 21, 2006 at 11:19 am
thanks for your reply. I figured it out, similar with yours but mine is longer.
February 21, 2006 at 2:13 pm
It's even more simple than you can imagine:
Logout - Login
If you need it for presentation purposes:
convert(varchar(8), Logout - Login, 108)
_____________
Code for TallyGenerator
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply