我需要计算销售数量,并按日期汇总销售总额,很容易。但是曲线间距是 - 我需要“截止”是下午 6 点而不是午夜。
前一天下午6点到当天下午6点。
让我失望的是“分组”。我的计数只提取真实日期而不是“下午 6 点”信息。
Sort30 Day30 Total Counter
-------- ---------- --------------------- -----------
20120810 08/10/2012 675.32 9
20120809 08/09/2012 1314.68 16
询问:
SELECT top 30 CONVERT(VARCHAR(8), chickendate, 112) AS varSort30,
CONVERT(VARCHAR(10), chickendate, 101) AS varDay30,
SUM(CAST(transAmount AS money)) AS varTotal,
Count(chickendate) AS varCounter
FROM CHICKEN
WHERE
(chickendate >= dateadd(hour, 18, dateadd(day, datediff(day, 0, chickendate), -1)) AND
chickendate < dateadd(hour, 18, dateadd(day, datediff(day, 0, chickendate), 0)))
GROUP BY CONVERT(VARCHAR(8), chickendate, 112),
CONVERT(VARCHAR(10), chickendate, 101)
ORDER BY CONVERT(VARCHAR(8), chickendate, 112) DESC
转来转去,我觉得有什么东西盯着我的脸。谢谢。