TRANSFORM Count(May18.ORDER_ID) AS CountOfORDER_ID
SELECT May18.DEPT
FROM [UPDATED POSITION] INNER JOIN May18 ON [UPDATED POSITION].DEPT = May18.DEPT
WHERE ((([UPDATED POSITION].SHIFT)="WEEKDAY_DAY") AND (((Weekday([INSTANT]))=1 Or (Weekday([INSTANT]))=7)=False) AND ((TimeSerial(Hour([Instant]),Minute([Instant]),0)) Between #12/30/1899 7:0:0# And #12/30/1899 15:0:0#))
GROUP BY May18.DEPT
PIVOT [UPDATED POSITION].POSITION;
我使用的数据是5月份的数据。我玩这个是和错误是在TimeSerial部分。我尝试添加“ Is Null”表达式,但丢失了许多实际上具有信息的数据
答案 0 :(得分:0)
我认为您正在使用此SQL:
TRANSFORM COUNT(May18.ORDER_ID) AS CountOfOrderID
SELECT May18.Dept
FROM [UPDATED POSITION] INNER JOIN May18 ON [UPDATED POSITION].DEPT = May18.DEPT
WHERE WEEKDAY(INSTANT,2)<6 AND TimeValue(Instant) BETWEEN #07:00:00# AND #15:00:00#
GROUP BY May18.Dept
PIVOT [UPDATED POSITION].POSITION
您有Weekday([INSTANT]))=1 Or (Weekday([INSTANT]))=7)=False
。这假定默认值为星期日为第1天,星期六为第7天。如果使用WEEKDAY(Instant,2)
,则假定星期一为第1天,星期日为第7天-因此,您只需要检查日期数是否小于6得到一个工作日。
SQL还忽略日期。要包含它,只需在WHERE
中添加另一个子句:
AND DateValue(Instant) = #09/17/2018#
(9月17日)或添加参数:
PARAMETERS MyDate DateTime;
TRANSFORM COUNT(May18.ORDER_ID) AS CountOfOrderID
SELECT May18.Dept
FROM [UPDATED POSITION] INNER JOIN May18 ON [UPDATED POSITION].DEPT = May18.DEPT
WHERE WEEKDAY(INSTANT,2)<6 AND
TimeValue(Instant) BETWEEN #07:00:00# AND #15:00:00#
AND DateValue(Instant) = MyDate
GROUP BY May18.Dept
PIVOT [UPDATED POSITION].POSITION