获取距离今天的连续日期天数

WITH    t AS ( SELECT   * ,
                        ( SELECT    DATEDIFF(d, '2015-05-25', CreateDate)
                          FROM      [dbo].[wx_usersignin] AS b
                          WHERE     b.CreateDate = a.CreateDate
                        ) AS day1 ,
                        ROW_NUMBER() OVER ( ORDER BY CreateDate DESC ) AS day2
               FROM     [dbo].[wx_usersignin] AS a
               WHERE    a.UserId = 10070
                        AND a.isJoin = 0
             )
    SELECT TOP 1
            SignDate ,
            day2
    FROM    t
    WHERE   day2 >= ABS(day1)
    ORDER BY CreateDate ASC

你可能感兴趣的:(获取距离今天的连续日期天数)