Advertisement

05.20.2008 at 04:26PM PDT, ID: 23419206
[x]
Attachment Details

How to get  the sum of Difference between two columns values using SQL Query

Asked by jisha123 in SQL Server 2005

Hi,
     I have a situation like this.I have a user login data table called LogTable where i have a set of Login, Logout date time details against a particular userid.The structure of LogTable is like this.
LogId (Primary key)
UserId(foreign key from user table)
Login_time(datetime)
LogoutTime(datetime)

The rows in this table is like this

LogId      UserId        LoginTime                       LogOutTime
1             23              5/20/2008 12:40AM        5./20/2008 1:10 AM
2             23              5/20/2008 1:15 AM         5/20/2008   2:10 AM
3             23              5/20/2008 2:15 AM         5/20/2008   3:20  AM
4             23              5/20/2008 3:40 AM         5/20/2008   4:00 AM

Here we can see a series of login, logouts by userid 23 , i need a sql query to calculate the total time the user spents in logging in (ie, sum (LogOutTime - LoginTime) for the 4 records, and also the total time in logging out for example the time the user logged out for the first time is 5/20/2008 1:15 - 5/20/2008 1:10 ie, 5 minutes.How can i find this using a sql query ? Please help
           
Start Free Trial
 
 
Loading Advertisement...
 
[+][-]05.20.2008 at 04:33PM PDT, ID: 21611162

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 04:52PM PDT, ID: 21611235

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 04:33AM PDT, ID: 21613852

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 07:58AM PDT, ID: 21615774

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 09:08AM PDT, ID: 21616478

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 09:14AM PDT, ID: 21616541

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: SQL Server 2005
Sign Up Now!
Solution Provided By: fesnyng
Participating Experts: 3
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628