问题
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