
数据库表结构如图所示,怎么样从这张表中按照chapterid字段区分按照不同比例随机提取值?例如chapterid=1的获取10个值,chapterid=2的获取20个值?
解决方案
20
(select *
from 数据库表结构如图所示
where chapterid=1
order by RAND() limit 10)
union all
(select *
from 数据库表结构如图所示
where chapterid=2
order by RAND() limit 20)
from 数据库表结构如图所示
where chapterid=1
order by RAND() limit 10)
union all
(select *
from 数据库表结构如图所示
where chapterid=2
order by RAND() limit 20)