SQL:计算名册中的差距

时间:2016-08-30 02:03:52

标签: sql sql-server

查看工作人员在名册中某一天没有工作的时间。名单表中的数据仅显示日期,开始时间和班次持续时间

以下脚本显示了为特定员工工作的每个班次的日期,开始和结束时间

代码:

select
date,
convert(time,[start time]) as starttime,
dateadd
(
minute,
duration * 5,
convert(time,[start time])
) as endtime
from roster where date = '2016/08/08' and [staff] = 'ME'  
order by starttime asc

结果:

  

2016/08/08 00:00:00.0000000 08:00:00.0000000

     

2016/08/08 09:00:00.0000000 09:45:00.0000000

     

2016/08/08 12:00:00.0000000 00:00:00.0000000

我想要的是

  

2016/08/08 08:00:00.0000000 09:00:00.0000000

     

2016/08/08 09:45:00.0000000 12:00:00.0000000

非常感谢任何帮助

谢谢!

1 个答案:

答案 0 :(得分:2)

大多数数据库都支持ANSI标准var json = '[{"var5":"item-company-1","asd2":"item-company-1","tie1":"0","cxs1":"481.891px","xcve2":"130.563px"},{"var5":"item-company-2","asd2":"item-company-2","tie1":"0","cxs1":"481.891px","xcve2":"130.563px"},{"var5":"item-company-3","asd2":"item-company-3","tie1":"0","cxs1":"481.891px","xcve2":"130.563px"}]'; var data = JSON.parse(json); for (var i = 0; i < data.length; i++) { console.log(i + ":"); for (var key in data[i]) { console.log(key, "=>", data[i][key]); } }功能。你似乎想要:

lead()