开发者

Query MySQL and Compare Entries?

开发者 https://www.devze.com 2023-03-15 03:34 出处:网络
I need to get a script working for our billing system (WHMCS) using their sample code that shows the average response time to support tickets for each month. Something like this already exists, howeve

I need to get a script working for our billing system (WHMCS) using their sample code that shows the average response time to support tickets for each month. Something like this already exists, however it gives a time based on all replies rather than just the first one. Since we put a lot of tickets on-hold, or flag them for other staff members, we would like to just be able to see how long on average the first response takes.

Here is an image of what the table looks like in the database. The psuedo code/logic would basically be find all of the "New Support Ticket Opened" entries and t开发者_如何学JAVAhen find the first entry after that for "New Ticket Response made by..." for that same ticket ID, and find the difference in in time between the dates.

I am not overly experienced with PHP/MYSQL though so could use some help to get this working. Thanks!

Query MySQL and Compare Entries?


The following SQL statement should get the results you're looking for:

SELECT b1.tid AS Tid, MIN(DATEDIFF(b2.date,b1.date)) AS ResponseTime
FROM billing b1 inner join billing b2 
ON b1.tid = b2.tid
WHERE b1.action='New Support Ticket Opened'
AND b2.action LIKE 'New Ticket Response made by%'
GROUP BY Tid

For learning how to connect to MySql and issue queries from PHP, I'll refer you to W3Schools.

0

精彩评论

暂无评论...
验证码 换一张
取 消