Sample Function

Database
Enthusiast

Sample Function

Hi,

I have an order table which has order details alongwith Product Code as "AS" , "BU" ,"CM","DQ","ER","FN"

I was to select a random of 10 records for each of the product codes "AS" , "CM" and "DQ"

Can i use a "sample" teradata feature to acheive the above results . If yes how can that be done in a single query, such that i get 30 records 10 each for the above 3 product codes.
Is there a better way to get the above results

Thanks,
Sam
6 REPLIES
Senior Apprentice

Re: Sample Function

Hi Sam,

select *
from tab
sample
when prod_code = 'AS' then 10
when prod_code = 'CM' then 10
when prod_code = 'DQ' then 10
end

Dieter
Enthusiast

Re: Sample Function

Thanks!

Sam

Re: Sample Function

If I want to get 10 samples for each prod_code, can this be done through 'sample' function in a single query?

Thanks!
Enthusiast

Re: Sample Function

Hi,

Iam a fresher in teradata.Iam able to join one source table to target table.But iam unable to join many source table to target source in a single query.
Senior Apprentice

Re: Sample Function

Why do you post this question in a thread about SAMPLE?

As Teradata uses Standard SQL you join multiple tables using multiple JOINs:

from t1
join t2 on t1.col1 = t2.col1
join t3 on t1.col3 = t3.col3
join t4 on t1.col4 = t4.col4
...

Dieter

Re: Sample Function

Hi 

If i need to do a sample but i I'm not quite sure about the values about i need to do the sample I mean I know the field that i need

But the values can change in any moment; can i do the sample function dinamic?

I know i can do wih a rank or rowNumber but because my result is for stadistic analisis it have to be Random 

Tnks