SELECT dttime, SUM(a.price) '销售额',count(1) '订单数'
FROM (SELECT CASE
WHEN DATEPART(mi, o.create_at) < 30
THEN
CONVERT(DATETIME,CONVERT(NVARCHAR(50), create_at, 23) +' '+CONVERT(VARCHAR(50),DATEPART(hh, create_at))+':00:00')
ELSE
CONVERT(DATETIME,CONVERT(NVARCHAR(50), create_at, 23) +' '+CONVERT(VARCHAR(50),DATEPART(hh, create_at))+':30:00')
END 'dttime',*
FROM dbo.[order](NOLOCK) o
WHERE create_at >= '2018-07-11' and create_at<'2018-07-12') a
GROUP BY dttime
05-11 15:15