RANDOM Function Example | Teradata Vantage - Example: Returning Random Integer Numbers as Results - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-30
dita:mapPath
tpt1555966086716.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1145
lifecycle
previous
Product Category
Teradata Vantageā„¢

Suppose you have a table named sales_table with the following subset of columns.

Store_ID Product_ID Sales
1003 C 20000
1002 C 35000
1001 C 60000
1002 D 50000
1003 D 50000
1001 D 35000
1001 A 100000
1002 A 40000
1001 E 30000

The following SELECT statement returns a random number between 1 and 3, inclusive, for each row in the results table.

   SELECT store_id, product_id, sales, RANDOM(1,3)
   FROM sales_table;

The results table might look like this.

Store_ID Product_ID Sales RANDOM(1,3)
1003 C 20000 1
1002 C 35000 2
1001 C 60000 2
1002 D 50000 3
1003 D 50000 2
1001 D 35000 3
1001 A 100000 2
1002 A 40000 1
1001 E 30000 2