Opened 16 years ago
Last modified 11 years ago
#8354 new enhancement
Report Query with dates
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | unscheduled |
Component: | report system | Version: | none |
Severity: | major | Keywords: | reports examples of SQL |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Hello, Based on the reports wiki page, trac wants to disable the reports in future version? For now the only way to save a query out of the box is via report. Below I will copy paste some reports that would be nice to include in the reports wiki as a custom advenced query examples. It took me over a week to get to this point. If what I supply here you can start doing queries in few minutes.
Some ideas taken from ticket #2288
Most of the problems come with knowing the fields which these examples show, and manipulating the date and date functions for particular database api. Below you will find examples on sqlite and mysql date functions and how to convert from timestamp.
sqlite:
recently closed
select id, summary, component, milestone, owner, (select max(tc.time) from ticket_change tc where t.id = tc.ticket and field = 'status' and newvalue = 'closed') as closetime, datetime((select max(tc.time) from ticket_change tc where t.id = tc.ticket and field = 'status' and newvalue = 'closed'), 'unixepoch', 'localtime') as closedate from ticket t where status = 'closed' and closetime > strftime('%s',datetime("now","-30 days"))+0 order by closetime
Mysql: Open ticket count by milestone. This is somewhat management report to see how many tickets are coming in daily.
SELECT version as __group__,DATE(FROM_UNIXTIME(time)) as Created, milestone, count(*) AS 'Count of Tickets' FROM ticket WHERE time > UNIX_TIMESTAMP(NOW() - INTERVAL 7 DAY) GROUP BY version,DATE(FROM_UNIXTIME(time)),(milestone IS NULL), milestone ORDER BY version,DATE(FROM_UNIXTIME(time)) DESC ,(milestone IS NULL), milestone
sqlite version
SELECT version __group__ ,date(time,'unixepoch', 'localtime') as Created,milestone, count(*) AS 'Count of Tickets' FROM ticket WHERE time > strftime('%s',datetime("now","-7 days"))+0 GROUP BY version,date(time,'unixepoch', 'localtime'),(milestone IS NULL), milestone ORDER BY version,date(time,'unixepoch', 'localtime') DESC ,(milestone IS NULL), milestone
I'll try to attach the remaining reports that I still need to do. IF you have any popular reports please paste them in here.
What I need:
- Closed tickets count by day and milestone,
- Open tickets count by milestone
- Active ticket count by user
- Closed ticket count by user who closed it.
If you have any of these done, or something similar please past it in.
Thanks, Lucas
Attachments (0)
Change History (7)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Samples from mailing list. Verified by user on the mailing list to work.
This would give you all closed tickets in the last 1 month:
SELECT DISTINCT id AS ticket, time, owner, version, milestone, resolution, status FROM ticket t WHERE status IN ('closed') AND time >= (select strftime ("%s", "now", "-1 month")) ORDER BY time
or if you wanted all in the current calendar month you could change the select line to:
AND time >= (select strftime ("%s", "now", "start of month"))
Another report I have is for selecting defects and enhancement tickets which were closed between two dates: _
select id, type, summary, component, milestone, owner, datetime((select max(tc.time) from ticket_change tc where t.id = tc.ticket and field = 'status' and newvalue = 'closed'), 'unixepoch', 'localtime') as closedate, (select max(tc.time) from ticket_change tc where t.id = tc.ticket and field = 'status' and newvalue = 'closed') as closetime from ticket t where status = 'closed' and closetime > strftime('%s',datetime('2006-03-24 16:38:45')) +0 and closetime < strftime('%s',datetime('2006-04-06 15:25:34')) +0 AND type IN ('defect','enhancement') order by -closetime;
comment:3 by , 15 years ago
Milestone: | → not applicable |
---|
comment:4 by , 15 years ago
Closed tickets by user (slow) This reports tells you how many tickets were closed by what user. At hight speed task tracking this is very useful measurement of performance.
select milestone, (select tc.author from ticket_change tc where t.id = tc.ticket and field = 'status' and newvalue = 'closed' order by tc.time DESC limit 1) as ModifiedBy, (DATE(FROM_UNIXTIME((select MAX(tc.time) from ticket_change tc where t.id = tc.ticket and field = 'status' and newvalue = 'closed')))) as closedate, count(*) AS 'Count of Tickets' from ticket t where t.status = 'closed' and (select MAX(tc.time) from ticket_change tc where t.id = tc.ticket and field = 'status' and newvalue = 'closed') > UNIX_TIMESTAMP(NOW() - INTERVAL 7 DAY) group by ModifiedBy,milestone,closedate order by ModifiedBy,milestone,closedate DESC
comment:5 by , 15 years ago
One more… Tickets Over 15 Days.
This report tells you what tickets are outstanding. You can pick a time frame based on you requirements. Any tickets over 15 days can be seen and user can make them critical if he believes its taking too long to fix them.
SELECT DATE(FROM_UNIXTIME(time)) as __group__,DATE(FROM_UNIXTIME(time)) as Created,version, milestone, count(*) AS 'Count of Tickets' FROM ticket WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 15 DAY) and status <> 'closed' GROUP BY DATE(FROM_UNIXTIME(time)),(milestone IS NULL), milestone,version ORDER BY DATE(FROM_UNIXTIME(time)) DESC ,(milestone IS NULL), milestone,version
comment:6 by , 15 years ago
Milestone: | not applicable → 2.0 |
---|---|
Summary: | Report Query Examples → Report Query with dates |
Recently Closed in mysql version (for manager)(count would be better):
My recently Closed. Working but might need more optimizing.
accepted tickets by user count , mysql version (needed to have a count of peoples workload)
Entered tickets by milestone, mysql (Good for daily count of how much work came in.)