6
I’m working with a database that contains all the tickets
registered in the otrs of the company where I work.
I intend 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 through all tickets opened between the day 2015-05-01 00:00:00
and 2015-05-01 23:59:59
, query will return tickets that have been opened and that have already been closed.
I am 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
;
What defines a ticket has been closed? You have a close date in your table?
– Pedro Camara Junior
Good morning Pedro, what defines a closed ticket is state_id when a ticket is opened a record is created in the ticket_history table as an open ticket if the ticket undergoes any changes always recorded in that table, and when it is closed a record as closed is created, ticket status passes to closed Successful in the state_id column
– user37233
So don’t just put it in your clause
WHERE
to consider only records that thestate_id
is different fromclosed
? Something like that:AND ts.state_id != closed_id
– Pedro Camara Junior
If it has been closed and reopened then are created two lines? If that is just set the Where by state_id = closed and the date. Is there a column that dictates the ticket status as closed, or opened directly by id?
– KhaosDoctor
Peter the problem is that if I enter it clause will give me the tickets that have already been open and are currently closed, because I am working with a table that records all changes of tickets
– user37233
Khaosdoctor in the ticket_history table are all states of tickets a ticket may have been opened at 10am today and have been closed at 11am there is a column in the ticket_history table that is called change_time that records the date and time of each change, yes whenever there is a change is recorded. with this clause will give me the tickets that have been opened but are now closed because that same day have already been open, and I just want you to give me the tickets that have state_id open
– user37233