There is no direct function in sql that chooses a random number between two numbers. But there is a function named rand(). This function gets no parameters, it returns decimal number between 0 and 1. With this function we can get random number between 1000 and 9999. You can see the code below…
Example -1
1 |
Select floor(rand()*9000) + 1000 |
The Explain of The Code above.
First rand metod executes, For example it returned 0,254587…. value. We multiply this number by 9000. 0,254587*8999 = 2291,283. Then floor method executes. This function rounds the value floor. Then we get the 2291 value.
Also you can see the related posts below….
Sql random number between 1 and 100