如果我的查询是mysql select * from Quiz
,我需要打印类似的内容
'mysql select * from Quiz where category = maths %50, physics %20
and chemistry %30
如何在Mysql查询中完成?请帮帮我
答案 0 :(得分:1)
这只能通过单独的SELECTs
来完成。但您可以使用UNION
将它们合并为一个。
(select * from Quiz where category='math' order by rand() limit 5)
union all
(select * from Quiz where category='physics' order by rand() limit 3)
union all
(select * from Quiz where category='chemistry' order by rand() limit 2)
您应该预先计算每个类别的问题数量。
另请注意,按rand()
排序对于大表来说是一种糟糕的方式。