-- ## 6: All Tickets By Milestone (Including closed) ## -- -- A more complex example to show how to make advanced reports. SELECT p.value AS __color__, t.milestone AS __group__, (CASE t.status WHEN 'closed' THEN 'color: #777; background: #ddd; border-color: #ccc;' ELSE (CASE t.owner WHEN $USER THEN 'font-weight: bold' END) END) AS __style__, t.id AS ticket, t.summary, t.component, t.status, t.resolution, t.version, t.type AS type, t.priority, t.owner, t.changetime AS modified, t.time AS _time, t.reporter AS _reporter FROM ticket t LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority' ORDER BY (t.milestone IS NULL), t.milestone DESC, (t.status = 'closed'), (CASE t.status WHEN 'closed' THEN t.changetime ELSE (-1) * CAST(p.value AS int) END) DESC