如何计算sql查询中的总工作小时数? [英] how to calculate the total hours worked in sql query?

查看:99
本文介绍了如何计算sql查询中的总工作小时数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

--ID-- DATE-- IN -- OUT--

    -- 10002-- 2015-07-07-- NULL-- 2015-07-07 16:30:10.000--

    --10002-- 2015-07-08-- 2015-07-08 07:23:50.000-- NULL--

    --10003-- 2015-07-08-- 2015-07-08 07:23:50.000-- 2015-07-08 16:23:50.000--





如果计算不同日期和使用sql之日的总工作时间怎么计算?

我已经使用了一个使用datediff的方法,但我不知道如何选择日期是否不同



how to calculate the total working hours if a different date and at the date of using sql ?
I already use a method by using datediff, but I do not know how to select if the date is different

推荐答案

如果我正确理解你的问题,你需要从两个不同的行中获取值。如果是这种情况,一种方法是在select语句中使用该表两次。换句话说就像(伪代码)



If I understand your question correctly, you need to fetch value from two different rows. If that is the case, one way is to use the table twice in the select statement. In other words something like (pseudo code)

select ...
from tablename a,
     tablename b
where a.id = b.id
and   b.in = (select min(c.in)
              from tablename c
              where c.id = a.id
              and   c.in > a.out)



根据数据库版本的不同,您可以使用 LAG 功能。看看如何从中获取数据结果集中的上一行或下一行 [ ^ ]


这篇关于如何计算sql查询中的总工作小时数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆