I use OTRS helpdesk ticket management system. When I execute the following query:
SELECT `ticket`.`id` , `ticket_history`.`ticket_id` , `ticket_history`.`id` , `ticket_history`.`name` , `ticket_history`.`create_time` FROM `ticket_history` INNER JOIN `ticket` ON `ticket_history`.`ticket_id` = `ticket`.`id` WHERE `ticket_history`.`name` LIKE '%Raw% %new%' OR `ticket_history`.`name` LIKE '%Close' ORDER BY `ticket_history`.`ticket_id` , `ticket_history`.`id` ASC
I get the following output:
+ ---- + ----------- + ----- + -------------------------- ----------------- + --------------------- +
| id | ticket_id | id | name | create_time |
+ ---- + ----------- + ----- + -------------------------- ----------------- + --------------------- +
| 1 | 1 | 79 | %% Close | 2013-06-10 11:50:33 |
| 2 | 2 | 2 | %% 2013060810000011 %% Raw %% 3 normal %% new %% 2 | 2013-06-08 21:59:02 |
| 3 | 3 | 5 | %% 2013060810000021 %% Raw %% 3 normal %% new %% 3 | 2013-06-08 21:59:03 |
| 3 | 3 | 22 | %% Close | 2013-06-08 22:10:41 |
| 3 | 3 | 82 | %% Close | 2013-06-10 11:50:49 |
| 4 | 4 | 88 | %% Close | 2013-06-10 11:51:32 |
| 5 | 5 | 64 | %% 2013060910000019 %% Raw %% 3 normal %% new %% 5 | 2013-06-09 17:12:09 |
| 5 | 5 | 85 | %% Close | 2013-06-10 11:51:10 |
| 6 | 6 | 92 | %% 2013061010000016 %% Raw %% 3 normal %% new %% 6 | 2013-06-10 12:00:24 |
| 7 | 7 | 95 | %% 2013061010000025 %% Raw %% 3 normal %% new %% 7 | 2013-06-10 13:05:05 |
| 8 | 8 | 98 | %% 2013061110000014 %% Raw %% 3 normal %% new %% 8 | 2013-06-11 19:05:06 |
| 8 | 8 | 109 | %% Close | 2013-06-17 23:57:35 |
| 9 | 9 | 163 | %% 2013061810000011 %% Raw %% 3 normal %% new %% 9 | 2013-06-18 02:05:06 |
+ ---- + ----------- + ----- + -------------------------- ----------------- + --------------------- +
I need to modify the above request so that I can only list the lines of each ticket that has "% RAW %% new%" in the name, and at the same time the same ticket_id has a line that has "% Close" in it.
In other words, three lines of ticket_id 3, two lines of ticket_id 5 and two lines of ticket_id 8 should be displayed from the above output.
source share