如何减去通过递归 CTE 生成的日期的偏移量?

How to subtract an offset to dates generated through a recursive CTE?

如果特定日期没有数据,下面的查询使用递归 CTE 生成日期。我想对从前一天 7:15 到第二天 7:15 的每日停机时间总计进行分组,并在一个月内完成。这个查询工作正常,但我需要从每天减去 DATEADD(minute, -(7 * 60 + 15).

WITH dates as (
      SELECT CONVERT(date, 'Anydate') as dte
      UNION ALL
      SELECT DATEADD(day, 1, dte)
      FROM dates
      WHERE dte < 'Anydate + 1 month later'
     )
SELECT CONVERT(datetime,d.dte), ISNULL(SUM(long_stop_minutes), 0) AS downtime
FROM dates d LEFT JOIN
     long_stops_table b
     ON CAST(t_stamp as DATE) = d.dte AND Type = 'downtime'
GROUP BY CONVERT(datetime, d.dte)
ORDER BY CONVERT(datetime, d.dte) ASC;

只需减去适当的时间单位。这是一种方法:

SELECT d.dte, 
       COALESCE(SUM(lst.long_stop_minutes), 0) AS downtime
FROM dates d LEFT JOIN
     long_stops_table lst
     ON CONVERT(date, DATEADD(minute, -(7 * 60 + 15), lst.t_stamp) = d.dte AND
        lst.Type = 'downtime'
GROUP BY d.dte
ORDER BY d.dte ASC;

我认为没有理由将 dates.dte 转换为 datetime,所以我删除了转换。