Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[MySQL] [HowTo] Getting a random number between two values
Droid Offline
Android Developer
*******

Postări: 43
29
Alăturat: Dec 2011
Reputație: 0
Aprecieri acordate: 1
Primit 73 aprecier(i) în 17 post(ări)
#1
[MySQL] [HowTo] Getting a random number between two values
If you need to get a random number between two values using only MySQL, you can use the following syntax (in this example we want to get a random number between 1 and 10):

SQL Code
SELECT FLOOR(1 + (RAND() * 10));


Cod:
1
2
3
4
5
6
7
mysql> SELECT FLOOR(1 + (RAND() * 10));
+--------------------------+
| FLOOR(1 + (RAND() * 10)) |
+--------------------------+
|                        7 |
+--------------------------+
1 row in set (0.00 sec)


Reference: MySQL Documentation - Mathematical Functions

01-03-2014, 08:22 PM




User(s) browsing this thread: 1 Guest(s)