显示Trac报告的回复/评论数量

时间:2013-03-07 14:16:10

标签: report trac

我想为Active Ticket报告中显示的每张故障单添加一份回复计数。

这是我当前的查询:

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 个答案:

答案 0 :(得分: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

并非所有列名都需要包含表名,但知道它们的来源并没有什么坏处,特别是如果一个人对db模式知之甚少的话。

CASE表达式用于填写没有评论的故障单的“评论”列。否则这些细胞就会是空的。

而不是newvalue =''会在没有真实评论的情况下排除更改,例如更改所有者重新分配。

我更喜欢按票证ID订购,但这取决于打开票证的数量。