我正尝试在 impala 中抽取一张 table 的 20%。我在某处听说内置的 impala 采样功能有问题。
有没有办法将子查询传递给 impala limit 函数以对整个表进行 n% 的采样。
我有这样的东西:
select
* from
table_a
order by rand()
limit
(
select
round( (count(distinct ids)) *.2,0)
from table_a)
)
子查询给了我所有记录的 20%
最佳答案
我不确定 Impala 是否有特定的采样逻辑(某些数据库有)。但是你可以使用窗口函数:
select a.*
from (select a.*,
row_number() over (order by rand()) as seqnum,
count(*) over () as cnt
from table_a
) a
where seqnum <= cnt * 0.2;
关于sql - 如何将查询答案传递给限制函数 Impala,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51600420/