Select Distinct in Access? Syntax error

时间秒杀一切 提交于 2019-12-24 04:00:34

问题


I have this 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);

Which picks out average times of a jog per week. I would also like to include a count how many times jogged per week, which I'm trying to do by counting the jog_id where SomeTable could have 5 entries for one jog_id.

I have tried:

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);

But this is giving me Syntax error (missing operator) in query expression 'Count(distinct jog_id)'.

What am I missing?


回答1:


You can't do this in Access without using a sub-query.
EX:

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

Here is a detailed article on the topic:




回答2:


Access refuses to do good in nearly all circumstances, one of which is the support of the Count(distinct x).



来源:https://stackoverflow.com/questions/14530755/select-distinct-in-access-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!