sql 按年月分组

SELECT date_num/12 [year], date_num%12+1 [month], num 
FROM(
    SELECT YEAR(register_date)*12+MONTH(register_date)-1 date_num,count(*) num 
    FROM [user]
    GROUP BY YEAR(register_date)*12+MONTH(register_date)-1) as t

 

posted @ 2022-01-12 19:07  SHHHS  阅读(239)  评论(0编辑  收藏  举报