[英]SQL Oracle Combine records
I have a query which returns the time somebody was at work for. 我有一个查询,它返回某人上班的时间。 However this gives me multiple records for each person.
但是,这给了我每个人多个记录。 Is there a way to add together the times so that i have a total time for each employee.
有没有一种方法可以将时间加在一起,这样我就有了每个员工的总时间。
The query is: 查询是:
select
employee.first_name,
employee.last_name,
to_number( to_char(to_date('1','J') +
(time_sheet.finish_date_time - time_sheet.start_date_time), 'J') - 1) days,
to_char(to_date('00:00:00','HH24:MI:SS') +
(time_sheet.finish_date_time - time_sheet.start_date_time), 'HH24:MI:SS') time
from
employee
inner join
employee_case on employee.employee_id = employee_case.employee
inner join
time_sheet on time_sheet.employee_case = employee_case.employee_case_id
where
employee_case.case = 1;
The current output is: 当前输出为:
but i would like to combine the Steve Baid values into 1. 但我想将Steve Baid值合并为1。
Any ideas? 有任何想法吗?
Use || 使用|| to concat values like:
合并以下值:
select
employee.first_name,
employee.last_name,
sum (to_number( to_char(to_date('1','J') +
(time_sheet.finish_date_time - time_sheet.start_date_time), 'J') - 1)) days
from
employee
inner join
employee_case on employee.employee_id = employee_case.employee
inner join
time_sheet on time_sheet.employee_case = employee_case.employee_case_id
where
employee_case.case = 1;
GROUP BY employee.first_name, employee.last_name
I think you'll need to do this as nested queries: 我认为您需要将其作为嵌套查询来执行:
select
first_name,
last_name,
to_number( to_char(to_date('1','J') + (duration), 'J') - 1) days,
to_char(to_date('00:00:00','HH24:MI:SS') + (duration), 'HH24:MI:SS') time
from (
select
employee.first_name first_name,
employee.last_name last_name,
time_sheet_sum.duration duration
from
employee
inner join
(
select
distinct employee_case.employee_id employee_id,
sum(time_sheet.finish_date_time - time_sheet.start_date_time) duration
from
employee_case
inner join
time_sheet on time_sheet.employee_case = employee_case.employee_case_id
where
employee_case.case = 1
group by
employee_case.employee_id
) time_sheet_sum on employee.employee_id = time_sheet_sum.employee
);
NB: I haven't been able to test or verify this code. 注意:我无法测试或验证此代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.