湖南省城乡住房建设厅网站,小程序搭建需要什么,湖北工程建设招投标中心网站,甘肃路桥建设集团有限公司网站快递行业#xff0c;经常需要计算2个节点的时效#xff0c;有的计算自然日#xff0c;有时候需要计算去掉周末的时效#xff0c;计算自然日很简单#xff0c;用函数datediff 就可以了#xff0c;计算工作日时效#xff0c;我的实现方法如下#xff0c;借助了一个日期维…
快递行业经常需要计算2个节点的时效有的计算自然日有时候需要计算去掉周末的时效计算自然日很简单用函数datediff 就可以了计算工作日时效我的实现方法如下借助了一个日期维度表。 SELECT t0.[date_key] ,t1.date_key as date_key2 ,t0.[day_abbreviation] ,t0.[date_value] ,sum(case when t1.[day_abbreviation] in (Sat,Sun) or t1.is_holiday1 then 0 else 1 end )as 间隔天数 into #a FROM [Data_Magic].[dbo].[dim_date] t0 left join [Data_Magic].[dbo].[dim_date] t1 on t1.[date_value]t0.[date_value] and t1.[date_value]2023-04-13 where t0.[date_value]2023-04-01 and t0.[date_value]2023-04-14 group by t0.[date_key] ,t0.[day_abbreviation] ,t0.[date_value] ,t1.date_key select a.DATE_KEY,a.date_key2,sum(b.间隔天数) 间隔天数 from #a a left join #a b on b.date_key2a.date_key2 and b.date_keya.date_key group by a.DATE_KEY,a.date_key2 order by date_key,date_key2 用的维度表如下 返回结果如下根据实际情况可以调整。