RANDOM Function Example | VantageCloud Lake - Example: Returning Random Integer Numbers as Results - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

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 may 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