我有这个 SQL:
SELECT (Min(Time_In) & " to " & Max(Time_Out)) AS [Week Of],
Round((Sum(DATEDIFF("n", Time_In, Time_Out))/Count(DATEDIFF("n", Time_In, Time_Out))),2) AS [Avg Min of Jog]
FROM SomeTable
WHERE len(Time_In) > 0 AND len(Time_Out) > 0
AND #01/01/2012# <= Time_In AND #12/31/2012# >= Time_In
GROUP BY DatePart('ww',Time_In);
其中选择了每周慢跑的平均时间。我还想计算每周慢跑多少次,我试图通过计算jog_id
whereSomeTable
可能有 5 个条目来计算一个jog_id
。
我努力了:
SELECT (Min(Time_In) & " to " & Max(Time_Out)) AS [Week Of],
Round((Sum(DATEDIFF("n", Time_In, Time_Out))/Count(DATEDIFF("n", Time_In, Time_Out))),2) AS [Avg Min of Jog],
Count(distinct jog_id) AS [Num Jogs]
FROM SomeTable
WHERE len(Time_In) > 0 AND len(Time_Out) > 0
AND #01/01/2012# <= Time_In AND #12/31/2012# >= Time_In
GROUP BY DatePart('ww',Time_In);
但这给了我Syntax error (missing operator) in query expression 'Count(distinct jog_id)'.
我错过了什么?