Teradata provides SAMPLE clause to return specific number/percentage of random rows containing required samples of data from the query resultset. There are many option available to use along with SAMPLE clause but this tutorial will cover only 2 simple variations. Table along with data used in the below examples can be found here.
select emp_no, emp_name, salary from employee SAMPLE 2;
Output:
emp_no emp_name salary
------- -------- -------
1000276 JONES 2975.00
1000315 TURNER 1500.00
select emp_no, emp_name, salary from employee SAMPLE .5;
Output:
emp_no emp_name salary
------- -------- -------
1000292 FORD 3000.00
1000315 TURNER 1500.00
1000288 SCOTT 3000.00
1000299 ALLEN 1600.00
1000326 ADAMS 1100.00
1000245 PRADEEP 5000.00
1000312 MARTIN 1250.00
select emp_no, emp_name, salary,job_title from employee
SAMPLE WHEN job_title='MANAGER' THEN 1
WHEN salary < 2500 THEN 0.2
ELSE 1
END;
Output:
emp_no emp_name salary job_title
------- --------- ------- -----------
1000326 ADAMS 1100.00 LDC
1000276 JONES 2975.00 MANAGER
1000336 JAMES 950.00 LDC
1000262 CLARK 2450.00 MANAGER