gpt4 book ai didi

sql - 您试图在 ms access 中执行不包含指定表达式 'out_time' 作为聚合函数的查询

转载 作者:行者123 更新时间:2023-12-04 18:47:13 24 4
gpt4 key购买 nike

我使用 Ms access 作为我的数据库,我正在使用以下查询来获取工作时间:

select 
in_time,
out_time,
datediff("n",b.in_time,c.out_time) as work_time,
log_date,
emp_id
from
(select
LogTime as in_time,
SrNo,
LogID as emp_id,
LogDate as log_date
from LogTemp
where Type='IN' ) as b
left join
(select
SrNo as out_id,
LogTime as out_time,
LogID as out_emp_id,
LogDate as out_log_date
from LogTemp
where Type = 'OUT'
group by SrNo) as c
on (b.SrNo <> c.out_id
and b.emp_id = c.out_emp_id
and b.log_date = out_log_date )
where
c.out_id > b.SrNo and
[log_date] >= #8/20/2012# and
[log_date] <= #8/20/2012# and
emp_id = "8"
group by b.SrNo;

但是当我执行查询时,我收到以下错误:
"you tried to execute a query that does not include the specified expression 'out_time'
as an aggregate function in ms access" error.

任何我犯错误的建议。

最佳答案

您有几个错误,以防您尝试执行 GROUP BY .首先检查MSDN for GROUP BY syntax, recommendations and samples .

基本上,如果您使用 GROUP BY,无需深入研究。 , SELECT 上的任何列不受聚合函数影响的子句 SUM , AVG等,应该出现在 GROUP BY 上条款。因此,在您的情况下,您应该添加:

LogTime as out_time,
LogID as out_emp_id,
LogDate as out_log_date

进入第二个子查询的 GROUP BY。并添加
 in_time,
out_time,
datediff("n",b.in_time,c.out_time) as work_time,
log_date,
emp_id

上主 GROUP BY在末尾。

但是,正如在一条评论中已经指出的那样,也许您想要做的是 ORDER BY .然后应该就像更换 GROUP 一样简单来自 ORDER它应该工作。只要确定这是你想要的。

关于sql - 您试图在 ms access 中执行不包含指定表达式 'out_time' 作为聚合函数的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12419917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com