<div dir="ltr"><div><div><div><div>Hi all,<br><br>I'm trying to put together a SQL query to present a view, that allows summaries of data to be performed in reporting tools. I have a feeling that this question has been asked before and answered, but my google-fu is failing me, so apologies in advance... I've only found questions about using RT-REST, for example (which I don't want to do).<br>
<br></div>I'm using RT 3.8.7 (yes I know it's old and it's in the pipeline to upgrade but we have a bunch of other systems that are integrated with RT and so it's not a simple "just upgrade RT" project for us.<br>
<br>Anyway, what I want to end up with is the following fields:<br><br></div>Tickets.EffectiveID<br>Queues.Name<br></div>Tickets.Owner<br></div><div>Transactions.Creator<br></div><div>Transactions.TimeTaken<br></div><div>
Transactions.Created<br></div><div>Tickets.Status<br></div><div>Tickets.Started<br></div><div>Tickets.Resolved<br></div><div>Tickets.Created<br></div><div>Transactions.Type<br><br></div><div>So i can easily point various reports at it and work from there.<br>
</div><div><br></div><div>the sql I'm using is...<br>SELECT<br>Tickets.EffectiveId AS TicketID,<br>Queues.`Name` AS Queue,<br>Tickets.`Owner` AS OwnerID,<br>Transactions.Creator AS TransactionCreatorID,<br>Transactions.TimeTaken AS TimeTaken,<br>
Transactions.Created AS TransactionCreated,<br>Tickets.`Status` AS TicketStatus,<br>Tickets.Started AS TicketStarted,<br>Tickets.Resolved AS TicketResolved,<br>Tickets.Created AS TicketCreated,<br>Transactions.Type AS TransactionType<br>
FROM<br>((((Tickets<br>JOIN Transactions ON ((Transactions.ObjectId = Tickets.id)))<br>JOIN Queues ON ((Queues.id = Tickets.Queue))))) <br><br></div><div>but I'm not getting the results I expect...<br></div><div><br></div>
<div>or even something far simpler like:<br>SELECT<br>Transactions.Creator,<br>sum(Transactions.TimeTaken/60) AS TimeInHours,<br>Month(Transactions.Created) AS TransactionMonth,<br>Year(Transactions.Created) AS TransactionYear<br>
FROM<br>Tickets JOIN Transactions ON Transactions.ObjectId = Tickets.id<br>where Transactions.Created > "2013-10-01"<br>group by Creator, Month(Transactions.Created), Year(Transactions.Created)<br><br></div><div>
just to try and compare the numbers... that I'm seeing with timeworked.pl...<br></div><div><br></div><div>Now my problem is that the numbers I'm getting don't match those returned by REST - for example using the <a href="http://timeworked.pl">timeworked.pl</a> script..<br>
</div><div><br></div><div>Is there a definitive SQL somewhere that I should use to return these?... and any pointers on what transaction types I should be avoiding or how to avoid double counting merged transactions I would be very grateful...<br>
<br></div><div>Thankyou!<br><br></div><div>Chris<br></div></div>