Home > database > Average order real-time send single problem
Average order real-time send single problem
Time:09-17
Recently in order to achieve an automatic single function, is to order an average assigned to existing employees (fixed) For example: [A, B, C, D] If he will be assigned to A order in the end [B, C, D, A] If E at this time there are new staff join in maintaining the current under the condition of insertion finally [B, C, D, E, A]
The order table Id status staff_id The status field (1 has sent 2 complete order)
The staff table Id name is_del
The current SQL is: SELECT Staff. Id The FROM ` ims_carwash_staff ` AS staff LEFT the JOIN ` ims_carwash_order ` AS ` order ` ON the staff. Id=order. Staff_id AND the order. The order_status=1 WHERE the staff. Is_del=0 GROUP BY the staff. Id ASC ORDER BY COUNT (ORDER id);
But there is A problem: if A staff at B staff has not been assigned to orders (status=1) when completed the task (status=2), the order will be assigned to A staff
CodePudding user response:
You mean there is no single priority, and then if you have already completed a single second, again according to the row of employees work number/name? If this is just in the sorting process: suppose order_status 0 no single, 1 have single, 2 complete, query the first completed singular sort again (can is full, also can be recently for a period of time) Select the top 1 * from XXX The order by order_status, complete the singular, staff work number or name