我正在使用WinSQL Lite并试图使用DATEPART,但我不确定如何

时间:2017-05-05 17:37:20

标签: winsql

我需要按小时为一个USER_ID对此SQL字符串进行分组,但我不确定如何使用我一直在阅读的DATEPART函数。 基本上,我想从他们开始工作到回家的时间获得该用户每小时的性能数据。如果用户在早上6点进来,我想看看他们的性能数据是在上午7点,早上8点,上午9点......等垂直分组,以便我可以将数据导入excel并制作图表。

-------EmpPerf--------

select u.user_id, SUM(tl.elapsed_time) AS ELAPSED, SUM(CASE WHEN 
(tl.standard_time = 0) THEN 0 ELSE (tl.elapsed_time) END)AS PERFTIME, 
SUM(tl.standard_time)as Standard_time

from perfplus.tale tl, perfplus.task tk, perfplus.users u

WHERE tl.task_id = tk.ID
AND tl.facility_id = tk.facility_id
AND tk.start_time BETWEEN {ts '2017-05-04 04:00:00'} and {ts '2017-05-05 03:59:59'}
AND tk.facility_id = '130'
AND tk.user_id = u.user_id
AND u.shift_name NOT IN ('9WMS','9','T2016','T2017')
and tk.status like ('TS_PROCESSED')
and u.user_id = 'LBRSHALL'

group by u.user_id

1 个答案:

答案 0 :(得分:0)

弄清楚了:

-------EmpPerf--------

select hour(tk.start_time), SUM(tl.elapsed_time) AS ELAPSED, SUM(CASE WHEN 
(tl.standard_time = 0) THEN 0 ELSE (tl.elapsed_time) END)AS PERFTIME, 
SUM(tl.standard_time)as Standard_time
from perfplus.tale tl, perfplus.task tk, perfplus.users u
WHERE tl.task_id = tk.ID
AND tl.facility_id = tk.facility_id
AND tk.start_time BETWEEN {ts '2017-05-04 04:00:00'} and {ts '2017-05-04 
23:00:00'}

AND tk.facility_id = '130'
AND tk.user_id = u.user_id
AND u.shift_name NOT IN ('9WMS','9','T2016','T2017')
and tk.status like ('TS_PROCESSED')
and u.user_id = 'LBRSHALL'

group by hour(tk.start_time)
order by hour(tk.start_time)