How to create a column in a select statement that has a random number in it?

Database
Highlighted
Enthusiast

How to create a column in a select statement that has a random number in it?

So I am creating a table in my data lab in teradata, see below:

Create table "T" as (SELECT DISTINCT IDs, year, customer zip code) with data.

 

I want to create a random number for each of my records so basically I want to create a column that has a random number for each of my rows.

 

how do I create that Column?

Thanks


Accepted Solutions
Teradata Employee

Re: How to create a column in a select statement that has a random number in it?

Use a derived table expression

CREATE TABLE T AS (SELECT ID, year, zip, RANDOM(lower_bound, upper_bound) AS rnum FROM (SELECT DISTINCT ID, year, zip FROM source) AS Z) WITH DATA
1 ACCEPTED SOLUTION
2 REPLIES
Teradata Employee

Re: How to create a column in a select statement that has a random number in it?

Use a derived table expression

CREATE TABLE T AS (SELECT ID, year, zip, RANDOM(lower_bound, upper_bound) AS rnum FROM (SELECT DISTINCT ID, year, zip FROM source) AS Z) WITH DATA
Enthusiast

Re: How to create a column in a select statement that has a random number in it?

Fred, This is perfect, Thanks a bunch!

Mike