2013-03-07 117 views
0

我想爲「活動故障單」報告中顯示的每張故障單添加回復計數。顯示Trac回覆/評論數量

這裏是我當前的查詢:

SELECT p.value AS __color__, 
    id AS ticket, summary, component, version, milestone, t.type AS type, 
    reporter, owner, status, 
    time AS created, 
    changetime AS _changetime, description AS _description, 
    date(changetime/1000000, 'unixepoch') as LastUpdate, 
    reporter AS _reporter 
    FROM ticket t 
    LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority' 
    WHERE status <> 'closed' 
    ORDER BY CAST(p.value AS integer), milestone, t.type, time 

是否有可能添加的回覆/評論數?

回答

1

使用子查詢它可能看起來像

SELECT p.value AS __color__, 
    id AS ticket, summary, component, version, milestone, t.type AS type, 
    reporter, owner, status, 
    time AS created, 
    changetime AS _changetime, description AS _description, 
    date(changetime/1000000, 'unixepoch') as LastUpdate, 
    reporter AS _reporter, 
    CASE WHEN c.count ISNULL OR c.count = '' THEN 0 ELSE c.count 
    END AS comments 
FROM ticket t 
LEFT JOIN (
    SELECT ticket, count(newvalue) AS count 
    FROM ticket_change 
    WHERE field = 'comment' AND NOT newvalue = '' 
    GROUP by ticket) AS c 
    ON t.id = c.ticket 
LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority' 
WHERE status <> 'closed' 
ORDER BY CAST(p.value AS integer), milestone, t.type, time 

並不是所有列名需要包括表名稱,但它不會傷害知道它們的來源,特別是如果一個人不知道太多關於分貝架構。

CASE表達式用於填充票據的「評論」列,但沒有評論。否則,這些單元將只是空的。

AND NOT newvalue =''排除沒有真正意見的更改,例如更改所有者重新分配。

我更希望通過機票ID訂購,但它取決於打開的機票數量。