我使用Ms访问作为我的数据库,我正在使用以下查询来获取时间:
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;
Run Code Online (Sandbox Code Playgroud)
但是当我执行查询时,我得到以下错误:
"you tried to execute a query that does not include the specified expression 'out_time'
as an aggregate function in ms access" error.
Run Code Online (Sandbox Code Playgroud)
我犯错误的任何建议.
你有几个错误,如果你想做一个GROUP BY
.首先检查MSDN的GROUP BY语法,建议和示例.
基本上,没有不断深入,如果你使用GROUP BY
,在任何列SELECT
条款不受聚集功能SUM
,AVG
等等,应该出现在GROUP BY
条款.所以在你的情况下你应该添加:
LogTime as out_time,
LogID as out_emp_id,
LogDate as out_log_date
Run Code Online (Sandbox Code Playgroud)
进入第二个子查询的GROUP BY.并添加
in_time,
out_time,
datediff("n",b.in_time,c.out_time) as work_time,
log_date,
emp_id
Run Code Online (Sandbox Code Playgroud)
在最后的主要GROUP BY
.
但是,正如已经在一条评论中指出的那样,也许你想做的是一个ORDER BY
.那么应尽可能更换容易GROUP
通过ORDER
,它应该工作.只要确定你想要的是什么.
归档时间: |
|
查看次数: |
12406 次 |
最近记录: |