📌  相关文章
📜  如何在sql server中获取同一字段中2个日期的日期差异 - SQL代码示例

📅  最后修改于: 2022-03-11 15:05:19.052000             🧑  作者: Mango

代码示例2
WITH Partitioned AS(    SELECT *, ROW_NUMBER() OVER (PARTITION BY cu_id, date ORDER BY cu_id, date) AS RowNumber    FROM @Table) SELECT     *,    CASE         WHEN RowNumber > 1 THEN 0        ELSE COALESCE(DATEDIFF(DAY, (SELECT MAX(date) FROM @Table WHERE date < a.date AND cu_id = a.cu_id), a.date), 0)    END AS Days_betweenFROM Partitioned a