Jump to content
php.lv forumi

Query with time count


cucumber

Recommended Posts

Ir tablula , kura ir

 

User Logtime

User Logofftime

 

un ir vajadzigs ieksh query aprekinat Logofftime - Logtime WHERE user='aaa' ?

Ar kadu f-ju palidzibu tas ir iespejams

Link to comment
Share on other sites

ieksh mysql pie query m jau aprekinat, paliek tik izvadit

Link to comment
Share on other sites

Ne biku savadak

 

+---------+-----------------------+
- Users   - Data				  -	
+---------+-----------------------+
- abc	 - 2006-07-12 20:21:20   - start time
- c	   -
- abc	 - 2006-07-13 10:21:20   - end time
- k	   -
- abc	 - 2006-07-14 08:11:20   - start time
- abc	 - 2006-07-14 10:21:20   - end time
+---------+------------------------+

 

sql vienmer bus abi laiki, tapec vajaga dabut piem usera abc kopigo laiku, cik kopa vinsh ir bijis sistema ?

Link to comment
Share on other sites

vai arī sessijas_id pielikt, jo citādi vienozīmīgi neatšķirsi kurš ieraksts ir kurai sessijai. sākumu un beigas var ar min un max atrast.

 

select
session_id,
user,
SEC_TO_TIME(unix_timestamp(session_end)-unix_timestamp(session_start)) as session_time
from ( select
 session_id,
 user,
 min(data) as session_start,
 max(data) as session_end
from test where user='abc'
group by session_id
) as t

Link to comment
Share on other sites

×
×
  • Create New...