如何在 Oracle SQL 中获取样本

How to get a sample in Oracle SQL

我有以下查询:

Select c.name, c.age, m.salary from customers c
left join money m on c.ID = m.ID and m.salary > 10000

where c.age > 50

现在我想获取 100 行的样本。我怎样才能做到这一点?我尝试使用 仅获取前 100 行,但这不会产生随机样本。

您可以在抓取之前进行随机排序:

Select c.name, c.age, m.salary
from customers c left join
     money m
     on c.ID = m.ID and m.salary > 10000
where c.age > 50
order by dbms_random.random()
fetch first 100 rows only;