I'm working with a database that contains all tickets
registered in the otrs of the company where I work.
I want to do a query where I return all tickets that were open in May.
The problem is that a ticket can be opened and closed on the same day and if you try to filter for all tickets opened between day 2015-05-01 00:00:00
and 2015-05-01 23:59:59
, the query will return the tickets that were opened and have already been closed.
I'm working with the following tables
- ticket_history
- ticket_state
- ticket_type
- ticket_history_type
- ticket_state_type
I have the following query:
SELECT
th.id,
th.name,
th.history_type_id,
th.ticket_id,
th.type_id,
th.queue_id,
th.state_id,
th.create_time,
th.change_time
FROM
sapec_db.ticket_history as th
left join ticket_state ts
on th.state_id=ts.id
left join ticket_type tt
on th.type_id=tt.id
WHERE
th.change_time between '2015-05-01 00:00:00' and '2015-05-31 23:59:59'
-- 4 Incident
and tt.name like 'Incident'
-- 1 new 4 open
and ts.name like 'open'
group by
ticket_id
;