3

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

伪代码就像

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

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

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

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

4

3 回答 3

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') 

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

于 2009-02-25T12:44:00.880 回答
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')
于 2009-02-25T12:54:21.370 回答
0

另外,关于表结构,这里你去:

CREATE TABLE ticket_change ( 
    ticket   INTEGER,
    time     INTEGER,
    author   TEXT,
    field    TEXT,
    oldvalue TEXT,
    newvalue TEXT,
    UNIQUE ( ticket, time, field ) 
);
于 2011-04-04T03:35:56.543 回答