Tag - 统计

SqlServer 统计 DB    2017-07-19 22:10:19    855
一、正常的时间格式

SELECT StartTime,CONVERT(datetime,case when datepart(mi,StartTime)<30 then CONVERT(varchar(100), StartTime, 23)+ ' ' +datename(hh,StartTime)+':00:00' else CONVERT(varchar(100), StartTime, 23)+ ' ' +datename(hh,StartTime)+':30:00' end) as HourPart 
   FROM
   WGS_MainCDR_201401
   TEMP
   GROUP BY StartTime,CONVERT(datetime,case when datepart(mi,StartTime)<30 then CONVERT(varchar(100), StartTime, 23)+ ' ' +datename(hh,StartTime)+':00:00' else CONVERT(varchar(100), StartTime, 23)+ ' ' +datename(hh,StartTime)+':30:00' end)
   
    结果如下:
   StartTime                           HourPart
2014-01-16 01:59:25.203 2014-01-16 01:30:00.000
2014-01-16 01:59:30.627 2014-01-16 01:30:00.000
2014-01-16 01:59:35.297 2014-01-16 01:30:00.000
2014-01-16 01:59:46.063 2014-01-16 01:30:00.000
2014-01-16 02:00:15.327 2014-01-16 02:00:00.000
2014-01-16 02:00:19.157 2014-01-16 02:00:00.000
2014-01-16 02:27:46.327 2014-01-16 02:00:00.000
2014-01-16 02:28:46.327 2014-01-16 02:00:00.000
2014-01-16 02:39:31.000 2014-01-16