2

我有这个 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_idwhereSomeTable可能有 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)'.

我错过了什么?

4

2 回答 2

5

如果不使用子查询,您将无法在 Access 中执行此操作。
前任:

SELECT Count(*)
FROM
(SELECT DISTINCT Name FROM table1);

是有关该主题的详细文章:

于 2013-01-25T21:38:51.740 回答
-1

Access 在几乎所有情况下都拒绝做好事,其中之一就是Count(distinct x).

于 2013-01-25T21:37:42.970 回答