[英]Jet SQL/MS Access - Query, count of tasks, sum of time, by user
I would really appreciate help in achieving the correct output, I want to understand how it works and self teach. 我非常感谢帮助获得正确的输出,我想了解它的工作原理并自学。
I have one table: 我有一张桌子:
I would like to achieve the below results from one query: 我想通过一个查询实现以下结果:
user_name | task | CountOftask | SumOftime
U1 1 1 00:15
U2 1 1 00:25
U2 2 1 00:05
U3 2 1 00:20
U3 3 2 00:40
The time field is date/time hh:nn. 时间字段是日期/时间hh:nn。 The date field is irrelevant for the query at this stage - I want all historic data returned.
在此阶段,日期字段与查询无关-我希望返回所有历史数据。
I would like to see a Count of task, SUM of time and Group by user_name & task, using one query with a sub select, instead of two separate queries. 我想使用一个带有子选择的查询而不是两个单独的查询来查看任务计数,时间总和以及按用户名和任务分组。
Thanks for your time 谢谢你的时间
I can create this output, but I use two queries (Q1) to convert the time to integer, summing it. 我可以创建此输出,但是我使用两个查询(Q1)将时间转换为整数,并将其求和。 (Q2) using Q1 convert the integer back to time hh:mm.
(Q2)使用Q1将整数转换回时间hh:mm。
SELECT
user_name
, task
, Count(task) AS CountOftask
, Sum(CLng(24*60*CDate([time]))) AS time_mins
FROM tasks
GROUP BY user_name, task;
SELECT
[301 SF count of task].user_name
, [301 SF count of task].task
, [301 SF count of task].CountOftask
, [time_mins]\60 & Format([time_mins] Mod 60,"\:00") AS Time_sum
FROM [301 SF count of task]
;
I would like to be able to do this in one query, any advice is appreciated. 我希望能够在一个查询中做到这一点,任何建议表示赞赏。
Try with: 尝试:
Select
user_name,
Max(task) As max_task,
Count(*) As task_count,
CDate(Sum([time])) As total_time
From
YourTable
Group By
user_name,
task
Edit - if time is text: 编辑 -如果时间是文本:
Sum(CDate([time])) As total_time
or forced to date value: 或强制日期值:
CDate(Sum(CDate([time]))) As total_time
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.