16.20 - 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
16.20
Published
March 2019
Language
English (United States)
Last Update
2020-03-25
dita:mapPath
xzf1512079057909.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.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