0

入力

 userid           login time                               logout time
----------------------------------------------------------------------------
   1          2012-08-01 16:08:26                     2012-08-01 16:08:29
   2          2012-08-01 16:22:49                     2012-08-01 16:25:44
   3          2012-08-01 16:08:26                     2012-08-01 16:08:29
   3          2012-08-01 16:22:49                     2012-08-01 16:25:44
   3          2012-08-01 16:08:26                     2012-08-01 16:08:29
   4          2012-08-01 16:22:49                     2012-08-01 16:25:44

出力:

 userid        date         total time difference b/w login time and logout time
---------------------------------------------------------------------------------
   1        2012-08-01                         00:08:29
   2        2012-08-01                         1:25:44
   3        2012-08-01                         00;55;5
   4        2012-08-01                         1:25:44

私が試したクエリは次のとおりです。

SELECT distinct t.user_id, DATE_FORMAT(t.login_time,\'%d %b %Y\') AS datez,
       SEC_TO_TIME(SUM(TIME_TO_SEC(t.logout_time) - TIME_TO_SEC(t.login_time))) AS timediffe
from login_log t 
where user_id=5 
  AND login_time between '2012-08-01' AND '2012-08-2' 
GROUP BY t.user_id,datez
4

4 に答える 4

4

TIMEDIFF関数を次のように使用する必要があると思います。

SELECT t.user_id,
       DATE_FORMAT(t.login_time,'%d %b %Y') AS datez,
       SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(t.logout_time, t.login_time)))) AS timediffe
FROM tic_login_log t
WHERE user_id = 5
      AND login_time between '2012-08-01' AND '2012-08-2'
GROUP BY t.user_id,datez;
于 2012-08-27T08:07:17.343 に答える
1

'2012-08-01'の問題の必要な出力によると

select userid, date(login_time) as Date, sum(timediff(logout_time-login_time) as
'Logged in Time' where date(login_time)='2012-08-01' group by userid;

各ユーザーの日付バイスの合計ログイン時間

select userid, date(login_time) as Date, sum(timediff(logout_time-login_time) as
'Logged in Time'    group by userid,date(login_time);

各ユーザーの履歴にログインした合計時間

select userid, date(login_time) as Date, sum(timediff(logout_time-login_time) as
'Logged in Time' group by userid;
于 2012-08-27T09:30:46.983 に答える
0

次の方法を使用して時間差を見つけてください。

select TIMEDIFF(NOW(), '2012-06-20 06:24:43')
于 2012-08-27T08:19:26.470 に答える
0

メソッドを使用できますTIMEDIFF()

これを試して :

SELECT timediff(your_logout_time,your_login_time);

例 :-

SELECT timediff('2012-08-02 16:08:29','2012-08-01 16:08:26');

出力:-'24:00:03'

于 2012-08-27T08:34:49.063 に答える