Mysql: 当使用 union all 时,使用 order by 和 limit 到单独的查询中

Mysql: Use order by and limit into separate queries when using union all

我知道 MySql 语法不允许我们做我正在寻找的事情,但我正在寻求解决我的问题的方法。

我想 运行 多个查询并使用 union 来显示完整的数据集,方法是对每个查询使用 order by 和 limit。由于法律问题,我使用了假参数和表名。

select 
    x,
    y,
    z
from tbl1
where z = 'xxxx'
and y = 111
and x = 'text'
order by rand()
limit 11966
union all
select 
    x,
    y,
    z
from tbl1
where z = 'xxxx'
and y = 222
and x = 'text'
order by rand()
limit 3560
union all
select
.
.
.
.
.

有人知道解决这个问题的方法吗?

使用括号:

(select ... order by ... limit ...) 
union all
(select ... order by ... limit ...) 
union all
(select ... order by ... limit ...) 
union all
...