我有以下代码:
SELECT distinct userinfo.userid,userinfo.name,timeframe,deptname from EarlyOut
INNER JOIN userinfo ON USERINFO.USERID = earlyout.USERID
INNDER JOIN DEPARTMENTS ON DEPARTMENTS.DEPTID = EarlyOut.DEFAULTDEPTID
where date>='2015-02-01' and date<='2015-02-28' and
DEPARTMENTS.DEPTNAME = 'abc'
现在从上面的代码我得到以下答案:
userid name timeframe deptname
111 xyz 2015-02-05 08:00:00 abc
111 xyz 2015-02-10 09:15:00 abc
现在我想要following
输出:
userid name timeframe deptname
111 xyz 17:15:00 abc
我想要总时间
那我怎么能这样做?
答案 0 :(得分:3)
试试这个:
SELECT DISTINCT userinfo.userid,
userinfo.name,
Dateadd(ms, Sum(Datediff(ms, '00:00:00.000', timeframe)), '00:00:00.000') AS newtimeframe,
deptname
FROM EarlyOut
INNER JOIN userinfo
ON USERINFO.USERID = earlyout.USERID
INNER JOIN DEPARTMENTS
ON DEPARTMENTS.DEPTID = EarlyOut.DEFAULTDEPTID
WHERE date >= '2015-02-01'
AND date <= '2015-02-28'
AND DEPARTMENTS.DEPTNAME = 'abc'
GROUP BY userinfo.userid,
userinfo.name,
DEPARTMENTS.DEPTNAME