Reputation: 33
I'm working on a ticketing system where analysts will be assigned tickets based on a specific criteria.
When they first log in they will click on the Get Net Ticket button.
The tickets are assigned as follows:
So if they click Get Next it will look for oldest open, if none > select Pending today, if none > select oldest Ready.
Below is my query but it doesnt seem to be working reliably. Any suggestions?
SELECT *
FROM support_case
WHERE (
case_status = 'Pending'
AND case_queue = 'Software'
AND pendDate = '12/15/2011')
OR (
case_status = 'Open'
AND case_queue = 'Software')
OR (
case_status = 'Ready'
AND case_queue = 'Software')
ORDER BY lastUpdate ASC
LIMIT 0 , 1
Upvotes: 0
Views: 613
Reputation: 13354
This will sort them by support_case, then by oldest open.
Open will be sorted oldest->newest, followed by Pending sorted oldest->newest, then Ready sorted oldest->newest.
SELECT *
FROM support_case
WHERE (
case_status = 'Pending'
OR case_status = 'Open'
OR case_status = 'Ready' )
AND case_queue = 'Software'
ORDER BY support_case ASC, lastUpdate ASC
LIMIT 1
If you had different status values (that weren't nicely alphabetical), you could restructure your database, or add a new column, to give a numerical value to your case_status. Then you can add an ORDER BY case_status_value DESC
to your query.
So: 'Open' = 10 'Pending' = 5 'Ready' = 1
So that Open are returned first, then pending, then ready. Then you can query:
SELECT *
FROM support_case
WHERE (
case_status = 'Pending'
OR case_status = 'Open'
OR case_status = 'Ready' )
AND case_queue = 'Software'
ORDER BY case_status_value DESC,
lastUpdate ASC
LIMIT 1
See @konerak's comments below for another option that accomplishes the same, without the column structure changes.
Upvotes: 1