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
原文地址:https://www.cnblogs.com/lindajia/p/9295753.html
时间: 2024-10-30 08:58:15