<div dir="ltr">Jason this is brilliant! Thank you!</div><div class="gmail_extra"><br><br><div class="gmail_quote">On 4 March 2014 13:57, j.hubbard <span dir="ltr"><<a href="mailto:jason.hubbard@circles.com" target="_blank">jason.hubbard@circles.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Landon, below is some sql I wrote (I'm not too good at sql so some of it<br>
could probably be optimized). It pulls a bunch of fields both system and<br>
custom as well as the first comment on the ticket and names the columns<br>
something friendly. Also it compensates for timezones since the db is in<br>
UTC.<br>
<br>
Hopefully it helps.<br>
<br>
The custom fields I am pulling are "Priority" (not the built-in one) and<br>
"Category". I have two different "Category" custom fields from two<br>
different queues but I am showing them both in one column, hence the OR in<br>
the first custom field join statement below.<br>
<br>
Let me know<br>
<br>
<br>
<br>
--begin SQL--<br>
<br>
SELECT T.id, T.EffectiveId, DATE(CONVERT_TZ(T.Created, '+00:00', '-04:00'))<br>
as 'Day Created',<br>
CONVERT_TZ(T.Created, '+00:00', '-04:00') as Created, CONVERT_TZ(T.Resolved,<br>
'+00:00', '-04:00') as Resolved,<br>
WEEK(CONVERT_TZ(T.Created, '+00:00', '-04:00')) as week,<br>
MONTH(CONVERT_TZ(T.Created, '+00:00', '-04:00')) as Month,<br>
U3.Name as 'Requestor', U6.EmailAddress as 'Requestor Email', U5.RealName as<br>
'Requestor RealName',<br>
U4.City as 'Requestor City', U.name as 'Owner', U2.RealName as 'Owner<br>
RealName', Q.id as QueueID,<br>
Q.Name as 'Queue Name', T.Status, OOCF.Content as 'Priority',<br>
OCF.Content as 'Category', OCF.ObjectId, OCF.CustomField, T.Subject,<br>
TO_DAYS(IF(Resolved != '0000-00-00 00:00:00' AND<br>
Resolved != '1970-01-01 00:00:00',<br>
DATE(Resolved), CURDATE())) -<br>
TO_DAYS(DATE(T.Created)) as days_open<br>
FROM Tickets T<br>
LEFT JOIN Users U on U.id = T.Owner<br>
LEFT JOIN Users U2 on U2.id = T.Owner<br>
LEFT JOIN Queues Q on Q.id = T.Queue<br>
LEFT JOIN Users U3 on U3.id = T.Creator<br>
LEFT JOIN Users U4 on U4.id = T.Creator<br>
LEFT JOIN Users U5 on U5.id = T.Creator<br>
LEFT JOIN Users U6 on U6.id = T.Creator<br>
LEFT JOIN (ObjectCustomFieldValues OCF) on (OCF.ObjectId = T.id AND<br>
(OCF.CustomField = '3' OR OCF.CustomField = '5'))<br>
LEFT JOIN (ObjectCustomFieldValues OOCF) on (OOCF.ObjectId = T.id AND<br>
OOCF.CustomField = '4')<br>
WHERE Type = 'ticket'<br>
AND<br>
(<br>
Status IN ('open','stalled','new','autoclose','resolved','rejected')<br>
OR<br>
(<br>
Status = 'resolved'<br>
AND Resolved > DATE_SUB(CURDATE(), INTERVAL 30 DAY)<br>
)<br>
)<br>
ORDER BY T.id<br>
<br>
--end SQL--<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://requesttracker.8502.n7.nabble.com/MySQL-Question-joins-and-stuff-tp56822p56850.html" target="_blank">http://requesttracker.8502.n7.nabble.com/MySQL-Question-joins-and-stuff-tp56822p56850.html</a><br>
Sent from the Request Tracker - User mailing list archive at Nabble.com.<br>
<span class="HOEnZb"><font color="#888888">--<br>
RT Training London, March 19-20 and Dallas May 20-21<br>
<a href="http://bestpractical.com/training" target="_blank">http://bestpractical.com/training</a><br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div><span style="font-family:arial;font-size:small">Landon Stewart :: </span><a href="mailto:lstewart@iweb.com" style="font-family:arial;font-size:small" target="_blank">lstewart@iweb.com</a><br>
</div><span style="font-family:arial;font-size:small">Lead Specialist, Abuse and Security Management</span><br style="font-family:arial;font-size:small"><span style="font-family:arial;font-size:small">Spécialiste principal, gestion des abus et sécurité</span><br style="font-family:arial;font-size:small">
<span style="font-family:arial;font-size:small"><a href="http://iweb.com" target="_blank">http://iweb.com</a> :: +1 (888) 909-4932</span><br><div><span style="font-family:arial;font-size:small"><br></span></div><div><span style="font-family:arial;font-size:small"><br>
</span></div></div>
</div>