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

Teradata Vantageā„¢ - SQL Functions, Expressions, and Predicates

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
SQL_Functions__Expressions__and_Predicates.Upload_071421/djk1612415574830.ditamap
dita:ditavalPath
SQL_Functions__Expressions__and_Predicates.Upload_071421/wrg1590696035526.ditaval
dita:id
kby1472250656485

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