How to show due date column in the trac reports?

眉间皱痕 提交于 2019-12-06 05:36:15

Derek is quit there. Nevertheless, here is the working one:

SELECT p.value AS __color__,
owner AS __group__,
id AS ticket, severity, summary, component, milestone, t.type AS type, time AS created,
changetime AS _changetime, description AS _description,
reporter AS _reporter, c.value AS Duedate
FROM ticket t
LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
LEFT OUTER JOIN ticket_custom c ON t.id = c.ticket AND c.name = 'due_date'
WHERE status = 'assigned'
ORDER BY owner, p.value, t.type, time

Only you will have to replace the c.name value to match with your date fields name, if it's not 'due_date' like in my configuration.

Background: The 'ticket_custom' table definition is just one key-value-pair per row, as the call for the schema reveals:

sqlite> .schema ticket_custom
CREATE TABLE ticket_custom (
    ticket integer,
    name text,
    value text,
    UNIQUE (ticket,name)
);

Please note the primary key is not just the ticket number, but ticket (number) and (custom column) name combined. Hence an additional WHERE clause is required on the JOIN or you'll still get multiple rows - one for each custom field of all matching tickets. This is in contrast to the main table 'ticket', where all information for one ticket is in a single row.

You aren't specifying a join condition on ticket_custom. Therefore, it's doing a CROSS JOIN, which joins every record from ticket_custom to every record in the rest of your query. So if your ticket left join enum originally returned 100 rows, and ticket_custom has 20, you'll have 2000 resulting rows in your 2nd query.

You need to determine how ticket_custom relates to the other tables and provide an appropriate predicate. Most likely, it's something like this:

SELECT p.value AS __color__,
owner AS __group__,
id AS ticket, severity, summary, component, milestone, t.type AS type, time AS created,
changetime AS _changetime, description AS _description,
reporter AS _reporter, c.value AS Duedate
FROM ticket t
LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
LEFT JOIN ticket_custom c ON t.id = c.ticket_id
WHERE status = 'assigned'
ORDER BY owner, p.value, t.type, time

(See new LEFT JOIN line). The columns are a guess - you'll need to substitute whichever columns correctly relate the 2 tables.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!