Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count between rows

Status
Not open for further replies.

123458585

Programmer
Feb 27, 2007
4
SE
Hi

I have table that logs login and logout and look like this

User
Login timestamp
Logout timestamp

No to the problem
I whant to take out in second the time between every login times

Please help
 
Do you mean you want to know (A) how many seconds it was since the previous login, or (B) how many seconds each session is?

Date-time management is an area where many DBMS products are far from standard compliant! The SQL statements below are both ANSI/ISO standard compliant:

(A)[tt]
SELECT (login - (SELECT MAX(login) FROM loggtable AS l_sq
WHERE l_sq.user = l_main.user
AND l_sq.login < l_main.login)) SECOND(10)
FROM logtable AS l_main
[/tt]

(B)[tt]
SELECT (logout - login) SECOND(10)
FROM logtable
[/tt]

Note that USER is a reserved word in ANSI/ISO SQL. To avoid future problems when upgrading your DBMS, you'd better replace that column name, or double quote it (i.e. "user").
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top