首頁>Club>
7
回覆列表
  • 1 # 使用者3540351559407

    CREATE TABLE #tempzhihu1

    (UID BIGINT,

    LOADTIME DATETIME)

    INSERT INTO #tempzhihu1

    VALUES

    (201,"2017/1/1"),

    (201,"2017/1/2"),

    (202,"2017/1/2"),

    (202,"2017/1/3"),

    (203,"2017/1/3"),

    (201,"2017/1/4"),

    (202,"2017/1/4"),

    (201,"2017/1/5"),

    (202,"2017/1/5"),

    (201,"2017/1/6"),

    (203,"2017/1/6"),

    (203,"2017/1/7")

    SELECT UID, MAX(DAYS) AS ConsecutiveDays

    FROM(

    SELECT UID,count(GroupingSet) AS DAYS

    FROM

    (SELECT UID, LOADTIME,

    GroupingSet = DATEADD(DAY,-ROW_NUMBER() OVER(PARTITION BY UID ORDER BY LOADTIME), LOADTIME)

    FROM #tempzhihu1) T1

    GROUP BY UID,GroupingSet) T2

    GROUP BY UID

    DROP TABLE #tempzhihu1

  • 中秋節和大豐收的關聯?
  • 為什麼電動車一充電,家裡燈泡就燒壞,這是什麼原因?