选择“访问权限不同"?语法错误 [英] Select Distinct in Access? Syntax error

查看:62
本文介绍了选择“访问权限不同"?语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个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可能有5个条目.

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.

我尝试过:

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)'.

我想念什么?

推荐答案

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

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:

这篇关于选择“访问权限不同"?语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆