我执行sql查询时得到的输出是
的形式date punchin punchout
05/20/19 12:00 pm 2:00pm
05/20/19 2:20pm 4:00pm
05/20/19 4:30pm 5:30pm
05/20/19 8:30am 9:30am
05/20/19 9:45am 12:00 am
但所需的结果是
date punchin punchout
05/20/19 8:30am 9:30am
05/20/19 9:45am 12:00 am
05/20/19 12:00 pm 2:00pm
05/20/19 2:20pm 4:00pm
05/20/19 4:30pm 5:30pm
这是我到目前为止使用的SQL:
SELECT DISTINCT
P.PERSONID,
P.PERSONNUM,
P.PERSONFULLNAME,
P.HOMELABORLEVELNM5 AS STOREID,
CAST(T.EVENTDATE AS varchar(11)) AS Day,
RIGHT(T.STARTDTM, 8) + ' -' + RIGHT(T.ENDDTM, 8) AS SHIFT,
T.TIMEINSECONDS / 3600.00 AS [Hours Worked]
FROM VP_EMPLOYEEV42 AS P
INNER JOIN VP_TIMESHEETITMV42 AS T ON P.EMPLOYEEID = T.EMPLOYEEID
WHERE T.EVENTDATE >= '2016-12-01'
AND P.EMPLOYMENTSTATUS = 'ACTIVE'
AND P.HOMELABORLEVELNM5 IN ('8166', '8111', '8168', '8171', '8175', '8197', '8233', '8236', '8255', '8267', '8313', '8320', '8325', '8328''8331', '8333', '8334', '8335', '8336', '8337', '8339', '8340', '8341', '8344', '8346', '8348', '8359', '8360', '8361', '8362', '8363', '8364', '8365', '8366', '8367', '8368', '8369', '8370', '8372', '8374', '8375', '8376', '8377', '8379', '8380', '8386', '8391', '8392', '8393', '8394', '8395', '8396', '8413', '8415', '8416', '8427', '8444', '16992', '21036', '21043', '21066', '21067', '69902', '71021', '72046')
GROUP BY P.PERSONID,
P.PERSONNUM,
P.PERSONFULLNAME,
P.HOMELABORLEVELNM5,
T.EVENTDATE,
T.TIMEINSECONDS,
T.STARTDTM,
T.ENDDTM
ORDER BY P.HOMELABORLEVELNM5;