oracle - SQL Query to find difference between two times -
date | id | param_type 07-08-2012 10:10:53 am| 5613| input 07-08-2012 10:10:59 am| 5613| output 07-08-2012 10:16:34 am| 5624| input 07-08-2012 10:16:42 am| 5624| output 07-08-2012 08:09:08 am| 5503| input 07-08-2012 08:09:15 am| 5503| output
table name : emp_records
want display time difference between input
, output
,as single record.
for example :
date |id | param_type 07-08-2012 10:10:53 am| 5613| input 07-08-2012 10:10:59 am| 5613| output
as
id |difference 5613| 6 min
you can use lag
analytic function:
select id, ( output_date - input_date ) * 24 * 60 minutes_difference ( select id, "date" output_date, lag( case param_type when 'input' "date" end ) ignore nulls on ( partition id order "date" ) input_date, param_type emp_records ) param_type = 'output';
Comments
Post a Comment