My table contains fields that store
我的表包含存储的字段
- ticket
- sale date/time
- price
I need help on how to select only those tickets sold between 8:00 AM and 12:00 PM on a day-to-day basis for an entire month, without including any sales between 12:01 PM and 10:00 PM.
我需要帮助,如何只选择在上午8:00到下午12:00之间销售的整个月的门票,而不包括在下午12:01到晚上10:00之间的任何销售。
2 个解决方案
#1
0
Simple way to deal with events in given hours of day is to use DATEPART
在一天中的特定时段处理事件的简单方法是使用DATEPART
SELECT *
FROM TicketTable
WHERE DATEPART(hh, SaleDateTime) BETWEEN 8 AND 11
#2
1
Try something like
尝试类似的东西
SELECT SUM(Price) Total_Morning_Sales
FROM TableName
WHERE CAST(Sale AS TIME) > '07:59:59'
AND CAST(Sale AS TIME) < '12:00:01'
AND MONTH(Sale) = 5 --<-- Month Number here
#1
0
Simple way to deal with events in given hours of day is to use DATEPART
在一天中的特定时段处理事件的简单方法是使用DATEPART
SELECT *
FROM TicketTable
WHERE DATEPART(hh, SaleDateTime) BETWEEN 8 AND 11
#2
1
Try something like
尝试类似的东西
SELECT SUM(Price) Total_Morning_Sales
FROM TableName
WHERE CAST(Sale AS TIME) > '07:59:59'
AND CAST(Sale AS TIME) < '12:00:01'
AND MONTH(Sale) = 5 --<-- Month Number here