RANDOM Function Example | Teradata Vantage - Example: Returning Random Integer Numbers as Results - Analytics Database - Teradata Vantage

SQL Functions, Expressions, and Predicates

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
ft:locale
en-US
ft:lastEdition
2025-03-30
dita:mapPath
obm1628111499646.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
kby1472250656485
lifecycle
latest
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