3

我正在使用以下内容显示已关闭的票证,新关闭的票证位于顶部:

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

以下是当前显示的列:

Ticket
Summary
Component
Version
Milestone
Type
Owner
Status
Created

我想关闭的日期添加到报告视图(可能还有第三列显示日期差异)。我该怎么办?

4

2 回答 2

2

要在报告视图上显示字段,而不仅仅是 RSS 提要,请从列名称中删除前导下划线。changetime AS _changetime是违规行;尝试将其更改为changetime AS closed. 注意:您可能必须像datetime(changetime/1000000, 'unixepoch') AS closed.

要获得日期差异,请尝试减去两列,每列都包含在对 SQLitejulianday函数的调用中,例如julianday('now') - julianday(changetime/1000000, 'unixepoch') AS closedago.

于 2012-10-26T19:33:13.260 回答
1

添加关闭日期并不像我想象的那么简单。下面的例子会告诉你诀窍:

SELECT p.value AS __color__,
       ticket, summary, component, version, milestone, t.type, owner,
       t.time AS created,
       MAX(tc.time) as date
  FROM ticket_change tc
  LEFT JOIN ticket t ON tc.ticket=id
  LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
 WHERE field='status'
   AND newvalue='closed'
 GROUP by ticket
 ORDER BY tc.time DESC, t.time DESC, CAST(p.value AS integer), milestone, t.type

您需要 'ticket_change' 数据库表上的 JOIN 和最后一个排序以可靠地获得最后一个关闭日期。

于 2012-10-29T20:37:49.123 回答