drn5375 2016-01-20 09:43
浏览 26

总计登录时间

I am using MySQL 5.6 and want to calculate sum (in-mins) against below data through SQL statement:

third column for just information and means i am expecting 15 value

 
Status   Date_Time            Total_hours

LogIn 2016-01-14 00:00:00
LogOut 2016-01-14 09:00:00 9 LogIn 2016-01-14 10:00:00
LogOut 2016-01-14 14:00:00 4 LogIn 2016-01-14 16:00:00
LogOut 2016-01-14 18:00:00 2

hours Total ==>> 15

  • 写回答

1条回答 默认 最新

  • douyin6188 2016-01-20 10:07
    关注

    Updated to include your table and field names.

    SELECT
    loggedin.InOutStatus,
    MAX(loggedin.Date_Time) AS start_time,
    loggedout.Date_TimeAS end_time,
    TIMEDIFF(MAX(loggedin.Date_Time), loggedout.Date_Time)
    FROM empstatuslog AS loggedin
    INNER JOIN empstatuslog AS loggedout ON (loggedin.InOutStatus = loggedout.InOutStatus
                                         AND loggedout.Date_Time > loggedin.Date_Time)
    WHERE loggedin.InOutStatus= 'LogIn'
    AND loggedout.InOutStatus= 'LogOut'
    GROUP BY loggedin.InOutStatus
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大