2012-02-20 88 views
0

假设我有一个week_nbr和cust_id表。Teradata中组中的数据示例

假设我需要每周有500位客户的样本。

装聋作哑的方法是为每星期做:

select cust_id 
from week_cust 
sample randomized allocation 500 
where week_nbr=1 

什么是聪明的办法?也就是说,有没有办法让以下概念有效?

select week_nbr 
     ,random sample of 500 cust_id in this week 
from week_cust 

这是在Teradata上12

最佳,并且由于事先。

回答

0

它不看我,好像有可能使用sample条款来做到这一点。你应该可以通过类似的方式获得相同的结果:

select week_nbr, cust_id 
from week_cust 
qualify row_number() over (partition by week_nbr order by random(1, 10000)) <= 500