Home > OS >  Is there any way to group and random some data in one sql?
Is there any way to group and random some data in one sql?

Time:12-22

I have a table with id from 1 to 10, now I need to random some data from 1 to 2, 3 to 5 and 6 to 10, such as random select 1,4,9, is there any way using one sql to resolve it?

table with id cloumn pic

CodePudding user response:

SELECT tablename.*
FROM tablename
JOIN ( SELECT ROUND(1 * RAND()   1) random UNION ALL
       SELECT ROUND(2 * RAND()   3) UNION ALL
       SELECT ROUND(4 * RAND()   6) ) randoms ON tablename.id = randoms.random
  • Related