vendredi 22 mai 2020

How Do I Keep A Random Number From Changing Its Value In The Same Query After Being Generated In Redshift?

I'm using random() in redshift sql query to generate a column, however, when I use this column again in the same query, the values are not the same as the value they were first generated (i.e. every time you use this column again in the same query, sql will generate a new random number), I wonder if I can keep the value of this random number fixed once it is generated? Thanks!

A simple example to explain my issue:

select random() as a
     , a as b
     , a as c
     , a as d

I would expect the a in the above query should be the same every time it is used, however if you really run the query above, a, b, c and d are all different.




Aucun commentaire:

Enregistrer un commentaire