SQL 依日期與月份統計次數

  • 3785
  • 0

1.依每日做次數統計

2.當年度的每月次數統計

1.例,列出前100天的每日次數統計

select top 100 CAST(CreateDate AS DATE) as d, count(*) as '每日次數統計'
from TableName
GROUP BY CAST(CreateDate AS DATE)
order by d desc 

2. 例, 當年度的每月次數統計

select  MONTH(CreateDate) as Months ,count(*) as '每月次數統計'
from TableName
WHERE     YEAR(CreateDate) = '2019' 
GROUP BY  MONTH(CreateDate)