如何在Trac中的特定日期创建已关闭票证的报表

时间:2009-02-25 12:14:57

标签: sqlite trac ticket-system

我希望创建一个报告,列出在特定时间段内关闭的所有门票。

伪代码就像

SELECT * FROM tickets
WHERE closed AND date_closed = 'january 2009'

我无法解决的部分是date_closed = 'january 2009'

有没有办法在Trac中做到这一点?

我对特定的SQL语法不感兴趣,我可以自己编写时间限制。我不确定的是Trac的数据库结构。

3 个答案:

答案 0 :(得分:3)

SELECT * FROM ticket
WHERE status='closed' 
  AND date(changetime,'unixepoch') 
      BETWEEN date('YYYY-MM-DD') /* <- here goes your start date */
          AND date('YYYY-MM-DD') /* <- here goes your end date */

如果您想要特定月份:

SELECT * FROM ticket
WHERE status='closed' 
  AND date(changetime,'unixepoch') 
      BETWEEN date('2009-01-01','start of month') 
          AND date('2009-01-01','start of month','+1 month','-1 day') 

date('2009-01-01','start of month')是按日期指定的月份的第一天,date('2009-01-01','start of month','+1 month','-1 day')是该月的最后一天。

答案 1 :(得分:2)

SELECT DISTINCT ticket.* FROM ticket, ticket_change
 WHERE ticket.id = ticket_change.ticket
   AND ticket_change.field = 'status'
   AND ticket_change.newvalue = 'closed'
   AND strftime('%m', ticket_change.time, 'unixepoch') = '01';

如果你也知道这一年,你最好使用像vartec建议的表达式而不是strftime:

SELECT DISTINCT ticket.* FROM ticket, ticket_change
 WHERE ticket.id = ticket_change.ticket
   AND ticket_change.field = 'status'
   AND ticket_change.newvalue = 'closed'
   AND date(ticket_change.time,'unixepoch') 
       BETWEEN date('2009-01-01','start of month') 
           AND date('2009-01-01','start of month','+1 month','-1 day')

答案 2 :(得分:0)

另外,关于表结构,请转到:

CREATE TABLE ticket_change ( 
    ticket   INTEGER,
    time     INTEGER,
    author   TEXT,
    field    TEXT,
    oldvalue TEXT,
    newvalue TEXT,
    UNIQUE ( ticket, time, field ) 
);