在Access中选择Distinct?语法错误

时间:2013-01-25 21:34:00

标签: sql ms-access-2007

我有这个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 SomeTable 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); 的5个条目来计算。

我试过了:

Syntax error (missing operator) in query expression 'Count(distinct jog_id)'.

但是这给了我{{1}}

我错过了什么?

2 个答案:

答案 0 :(得分:3)

如果不使用子查询,则无法在Access中执行此操作 EX:

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

Here是关于该主题的详细文章:

答案 1 :(得分:-1)

Access几乎在所有情况下都拒绝行事,其中一个是Count(distinct x)的支持。