2009-02-25 72 views
3

我希望創建一份報告,列出在特定時間段內關閉的所有票證。如何在Trac中的特定日期創建關閉的票據報告

僞代碼將會像

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

我不能解決的部分是date_closed = 'january 2009'

有沒有辦法在Trac中做到這一點?

我對特定的SQL語法不感興趣,我可以自己寫時間限制。我不確定的是Trac的db結構。

回答

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

如果您也知道這一年,而不是strftime的你最好使用像vartec的表達建議:

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') 
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')是這個月的最後一天。

+0

最後更改可能是其他狀態。 – kmkaplan 2009-02-25 12:58:13

+0

好點kmkaplan。然而就我而言,我對目前關閉的門票很感興趣,所以「關閉」總是最後的改變。無論如何。你們兩個都幫了我很多。非常感謝。 – 2009-02-25 13:31:58

0

此外,關於表的結構,在這裏你去:

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