我需要帮助将下面的excel逻辑转换为SQL子查询。非常感谢您的帮助。
C栏
累计会议纪要
Excel公式
答案 0 :(得分:1)
这个怎么样:
WITH CTE(RowNumber, Date) AS(
select 1, '2012-01-10 16:22' union
select 2, '2012-01-10 16:24' union
select 3, '2012-01-10 16:25' union
select 4, '2012-01-10 16:26' union
select 5, '2012-01-10 19:27'
)
select b.Date, IIF(DATEDIFF(minute, a.Date, b.Date) > 45, 45, DATEDIFF(minute, a.Date, b.Date)) as AccumulatedMinutes
from CTE b left outer join CTE a on a.RowNumber = b.RowNumber - 1
它返回:
2012-01-10 16:22 NULL
2012-01-10 16:24 2
2012-01-10 16:25 1
2012-01-10 16:26 1
2012-01-10 19:27 45