【发布时间】:2019-03-28 17:42:37
【问题描述】:
我有一个 ABC 表,它有 10M+ 行。它包含 customer_id、email、score。我创建了一个随机选择 1,000 个数字并按组计数的查询。此查询的输出如下。
RANDOM_GROUP FREQ
1 71
2 45
3 35
4 45
5 53
6 40
7 65
8 54
9 68
10 59
11 465
这是我的查询:
select random_group, count(random_group) as freq
from
(select case when rand_num >= 0 and rand_num<=0.053 then 1
when rand_num > 0.053 and rand_num <= 0.097 then 2
when rand_num > 0.097 and rand_num <= 0.142 then 3
when rand_num > 0.142 and rand_num <= 0.189 then 4
when rand_num > 0.189 and rand_num <= 0.234 then 5
when rand_num > 0.234 and rand_num <= 0.281 then 6
when rand_num > 0.281 and rand_num <= 0.341 then 7
when rand_num > 0.341 and rand_num <= 0.399 then 8
when rand_num > 0.399 and rand_num <= 0.458 then 9
when rand_num > 0.458 and rand_num <= 0.515 then 10
when rand_num > 0.515 and rand_num <= 1.000 then 11 end
random_group
from
(SELECT dbms_random.value(0,1) AS rand_num,
rownum as at_row_num
FROM ABC
WHERE rownum <= 1000))
group by random_group
order by random_group
;
是否可以重复此查询 N 次,以便每个输出生成不同的计数?我应该使用循环吗?不想手动运行N次得到不同的结果...谢谢!
【问题讨论】: