
I'm sorry I posted a version of the query which is customized for our environment, I repost a the genarl query
SELECT t.tn, t.customer_id, t.create_time, MAX(th.change_time) AS change_time, DATEDIFF(MAX(th.change_time), t.create_time) AS open_days, TIMEDIFF(MAX(th.change_time), t.create_time) AS open_time
FROM ticket AS t JOIN ticket_history AS th ON t.id=th.ticket_id JOIN ticket_history_type AS tht ON th.history_type_id=tht.id
WHERE t.ticket_state_id=2 AND tht.id=27 AND th.name LIKE '%closed successful%'
AND t.customer_id LIKE '%'
GROUP BY t.id;
----- Original Message -----
From: Gabriele D'Andrea
To: User questions and discussions about OTRS.org
Sent: Tuesday, October 23, 2007 2:16 PM
Subject: Re: [otrs] Stats reports ?
I wrote a SQL query to do that.
This one queries the database for all closed succesful tickets, calculating the time between creation and closing.
SELECT tn, customer_id, create_time, freetime1 AS real_close_time, DATEDIFF(freetime1, create_time) AS open_days, TIMEDIFF(freetime1, create_time) AS open_time
FROM ticket
WHERE ticket_state_id=2 AND '2007-01-01'