SQL Query Limit for Each Status

Viewed 67

I have this query:

UPDATE `vicidial_list` 
SET list_id = 1000, 
    status = "NEW", 
    called_since_last_reset = "N" 
WHERE status IN ("DROP","ERI","NRP","RPD","OKQ","PDROP","PI","RCAT")              
ORDER BY RAND() LIMIT 500;

Now because every status has a different number of occurrences in the database, "DROP" has 8917 entries, while "PI" has 59044 entries, I want to make it consistent like, for example limiting the affected rows of "DROP" to 20, while limiting "PI" to 100 for every query, so all the statuses keep consistent.

I know I can do it like this:

UPDATE `vicidial_list` 
SET list_id = 1000, 
    status = "NEW", 
    called_since_last_reset = "N" 
WHERE status = DROP" 
ORDER BY RAND() LIMIT 20;

UPDATE `vicidial_list` 
SET list_id = 1000, 
    status = "NEW", 
    called_since_last_reset = "N" 
WHERE status = "PI" 
ORDER BY RAND() LIMIT 100;

But I want to know if there is a way to execute ONE query that contains all the limits for each status.

0 Answers
Related