DB/Postgresql
[postgresql]해당 범위의 랜덤한 숫자를 소수점 둘째자리수까지 뽑기, How to Generate a Random Number in a Range
JENN_tech7
2022. 8. 3. 14:56
728x90
SMALL
0과 1 사이의 난수를 반환하는 함수
SELECT random();
두 정수 A와 B사이의 난수 생성하기
SELECT floor(random() * (A-B+1) + B)::int;
나는 300에서 900까지의 소수점두자리수의 랜덤한 숫자를 뽑고 싶었기때문에
round(cast(random() * (400-300+1) + 300 as numeric),2)
이런식으로 만들어주었다
음 잘 뜨는군
참고 ref
https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-random-range/
How to Generate a Random Number in A Range
Summary: this tutorial shows you how to develop a user-defined function that generates a random number between two numbers. PostgreSQL provides the random() function that returns a random number between 0 and 1. The following statement returns a random num
www.postgresqltutorial.com
728x90
LIST