sql - 如何将查询答案传递给限制函数 Impala
问题描述
我正在尝试在 impala 中抽取 20% 的表格。我在某处听说内置的 impala 采样功能存在问题。
有没有办法将子查询传递给 impala 限制函数以对整个表的 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;
推荐阅读
- vb.net - vb.net 和 ms access 2016 登录表单
- python - 在python中填充数组
- android - Android 以编程方式获取应用的所有受支持的深层链接
- node.js - 如何完全停止节点下载文件
- git - git 目录上的 Magit-status 失败
- datetime - 孟加拉语(孟加拉语)日期和时间的日期时间格式?
- asp.net - 如何在 MVC 5 中将带有提交表单的部分视图设置为我的所有主视图?
- apache-spark - Spark SaveAsTextFile 返回错误 - Py4JJaveError
- css - 如何将较短的弹性内容拉到上面的行中
- javascript - 无法统一显示网格