Hi I wondered how to select a random set of 2% of all rows. I know that we can do it in such a way: 'LIMIT 100'. But the challenge here is that the table size changes, but I always want 2% of total rows by random, either rounding up or down is fine. The table has unique id for each row. Does anyone know how to do it?
SET @size := CEILING(0.02*(SELECT COUNT(*) FROM orders));
SELECT
*
FROM
`orders`
ORDER BY RAND()
LIMIT (SELECT @size)
I have tried using session variable, but the last line doesn't seem to work (LIMIT (SELECT @size))