sql按分时段统计

  SELECT SUBSTRING(replace(replace(replace(CONVERT(varchar, ScanTime, 120 ),'-',''),' ',''),':',''),9,3) ctime, count(1) num 
  FROM [eschool_1].[dbo].kg_Kaoqin  
  group by SUBSTRING(replace(replace(replace(CONVERT(varchar, ScanTime, 120 ),'-',''),' ',''),':',''),9,3)
  order by SUBSTRING(replace(replace(replace(CONVERT(varchar, ScanTime, 120 ),'-',''),' ',''),':',''),9,3)
原文地址:https://www.cnblogs.com/shiningrise/p/6535447.html