Esta solución realizará una suma acumulativa, deteniéndose cuando la suma exceda 1000:
SELECT NULL AS users_count, NULL AS total
FROM dual
WHERE (@total := 0)
UNION
SELECT users_count, @total := @total + users_count AS total
FROM messages_queue
WHERE @total < 1000;
Eso significa que si tiene dos valores de, digamos, 800, la suma total será 1600. El primer SELECT es solo para inicializar @total
variables.
Si desea evitar que la suma supere los 1000, excepto en los casos en que una sola fila tenga un valor superior a 1000, creo que esto funciona, aunque deberá someterlo a pruebas rigurosas:
SELECT NULL AS users_count, NULL AS total, NULL AS found
FROM dual
WHERE (@total := 0 OR @found := 0)
UNION
SELECT users_count, @total AS total, @found := 1 AS found
FROM messages_queue
WHERE (@total := @total + users_count)
AND @total < 1000
UNION
SELECT users_count, users_count AS total, 0 AS found
FROM messages_queue
WHERE IF(@found = 0, @found := 1, 0);