I have table as follows
tbl_tickets
id - INT primary key
ticket_id VARCHAR(80)
start_time DATETIME
end_time DATETIME
I want to work out the average transaction time (end_time - start_time) only on distinct records
This is the way I would do this:
Code:
SELECT AVG(datediff(ss, end_time, start_time))
FROM( SELECT DISTINCT ticket_id
, start_time
, end_time
FROM tbl_tickets) x
If the table had a million records the subquery would pull out a large chunk of data - isnt this inefficient? Is there any other way to do this more efficiently without redesigning the database?