用需要判断是否排序的Col减去ROW_NUMBER排序,然后作为PARTITION条件在窗口函数中计数即可。 SELECT * FROM ( SELECT DISTINCT author_id, author_level, COUNT(*) OVER(PARTITION BY author_id, const_col) AS days_cnt FROM ( SELECT *, DAY(answer_date) - ROW_NUMBER() OVER(PARTITION BY author_id ORDER ...