-- ## 9: Tickets from Help Desk ## -- -- SELECT p.value AS __color__, (CASE WHEN owner = $USER AND status = 'accepted' THEN 'Accepted' WHEN owner = $USER THEN 'Owned' WHEN reporter = $USER THEN 'Reported' ELSE 'Commented' END) AS __group__, t.id AS ticket, summary, component, version, milestone, t.type AS type, priority, t.time AS created, t.changetime AS _changetime, description AS _description, reporter AS _reporter FROM ticket t LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority' WHERE t.status <> 'closed' AND (lower(owner) = 'helpdesk' OR lower(reporter) = 'helpdesk' OR EXISTS (SELECT * FROM ticket_change tc WHERE tc.ticket = t.id AND lower(tc.author) = 'helpdesk' AND tc.field = 'comment')) ORDER BY (COALESCE(owner, '') = 'helpdesk' AND status = 'accepted') DESC, COALESCE(owner, '') = 'helpdesk' DESC, COALESCE(reporter, '') = 'helpdesk' DESC, CAST(p.value AS signed), milestone, t.type, t.time