(
SELECT * FROM your_table
WHERE difficulty = 'A'
ORDER BY RAND()
LIMIT 4
)
UNION ALL
(
SELECT * FROM your_table
WHERE difficulty = 'B'
ORDER BY RAND()
LIMIT 4
)
UNION ALL
(
SELECT * FROM your_table
WHERE difficulty = 'C'
ORDER BY RAND()
LIMIT 2
)
(
SELECT * FROM table
WHERE difficulty='A'
ORDER BY RAND()
LIMIT 4
)
UNION ALL
(
SELECT * FROM table
WHERE difficulty='B'
ORDER BY RAND()
LIMIT 4
)
UNION ALL
(
SELECT * FROM table
WHERE difficulty='C'
ORDER BY RAND()
LIMIT 2
);
2条答案
按热度按时间8yparm6h1#
不确定我是否完全理解你的问题,但我想这就是你想要的。
字符串
它由三个单独的
SELECT
语句组成,这些语句由UNION
连接。每个SELECT语句检索对应难度类型的指定数量的随机行。hmae6n7t2#
试试这样的方法:
字符串