I am not sure if this is possible but here goes.
I am using MySQL and need to complete a statement that produces an output as follows.
I have a table which contains a completeddate field and an enquirydate field.
I need to get data on the time difference between theses fields for which I have the following code
SELECT DATE (completedate) - DATE (enqdate) AS `timediff`, COUNT(*) AS TotalCount
FROM cia_enquiry
WHERE (DATEDIFF(CURDATE(), enqdate) < 30) AND completedate > 1
GROUP BY `timediff`
ORDER BY `timediff` ASC
The above code simply outputs a figure of days between the dates and the total count of entires within the last 30 days (and not counting those entries that are not complete)
I now need to reference the “timediff” results against another table and pull another field from that table.
For example if timediff = 1, then we need to find the id of 1 in another table and return the description field from this table.
Ultimately we should end up with something similar to
timediff TotalCount description
0 52 Within 24 hrs
1 13 24-48hrs
etc etc ………
It can be done; you have two choices
Option 1
Option 2
Hope this helps you