I am working on some reports about Sales given certain times, I have managed to get the sum of the sales given the day of the week, but i need further narrowing, I need to get the sum of each day of the week sales, that are made after 13:00.
我在某些时候正在制作一些关于销售的报告,我已经设法得到了一周中的销售总额,但我需要进一步缩小,我需要得到每周销售额的总和,是在13:00之后制作的。
This is the code used for getting the sum of the sales per day of the week
这是用于获取一周中每天销售总额的代码
SELECT
sum(ammount), datename (weekday,sale_date)
FROM SALES where sale_date > '2012-01-01 00:00:00'
group by datename (weekday,sale_date)
2 个解决方案
#1
2
You could add a condition for "after 13:00" to the where
clause:
您可以在where子句中添加“13:00之后”的条件:
where sale_date > '2012-01-01 00:00:00'
and datepart(hour, sale_date) >= 13
#2
1
Why not use the hh
part of DATEPART
?
为什么不使用DATEPART的hh部分?
SELECT Sum(ammount),
Datename (weekday, sale_date)
FROM sales
WHERE sale_date > '2012-01-01 00:00:00'
AND Datepart(hh, sale_date) >= 13
GROUP BY Datename (weekday, sale_date)
#1
2
You could add a condition for "after 13:00" to the where
clause:
您可以在where子句中添加“13:00之后”的条件:
where sale_date > '2012-01-01 00:00:00'
and datepart(hour, sale_date) >= 13
#2
1
Why not use the hh
part of DATEPART
?
为什么不使用DATEPART的hh部分?
SELECT Sum(ammount),
Datename (weekday, sale_date)
FROM sales
WHERE sale_date > '2012-01-01 00:00:00'
AND Datepart(hh, sale_date) >= 13
GROUP BY Datename (weekday, sale_date)