0

我想为活动工单报告中显示的每张工单添加回复计数。

这是我当前的查询:

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

是否可以添加回复/评论计数?

4

1 回答 1

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 表达式用于填充没有评论的工单的“评论”列。否则,这些单元格将是空的。

AND NOT newvalue = ''排除没有真正评论的更改,例如更改所有者重新分配。

我也更喜欢按票号订购,但这取决于开放票的数量。

于 2013-03-08T20:37:27.913 回答