在此查询中,我希望返回总共 x 条记录。在该查询中,我有几个子查询,我无法确定它们是否会返回最大记录数。如果一个结果小于它的最大限制,我想用下一个查询填充剩余的插槽,依此类推。我无法在限制子句中进行数学运算,所以我仍在试图弄清楚如何去做。如果在 limit 子句中可以使用数学,我会这样做。
select *
from
(
(select * from profile where size='local' order by rand() limit 7) as local
join
(select * from profile where size='regional' order by rand() limit (13-count(local.id)) as regional
join
(select * from profile where size='national' order by rand() limit (19-(count(local.id)+count(regional.id))) as national
join
(select * from profile where size='international' order by rand() limit (25-(count(local.id)+count(regional.id)+count(national.id)))) as international
)