Is there any function in SQL to get a random number in a given interval?
I need to populate a d开发者_如何学Catabase with random values between 50000 and 15000000 in SQL, someone know any function to do that?
Thanks
Which database are you using?
Here's how I'd do it on MS SQL Server, using the RAND
function:
DECLARE @MinValue INT
SET @MinValue = 50000
DECLARE @MaxValue INT
SET @MaxValue = 15000000
SELECT @MinValue + CAST(RAND() * (@MaxValue - @MinValue) AS INT)
check these URL sql-server-random-number-generator-script-sql-query for SQL Server
Different DBMSes provide different methods, such as RAND() on MySQL and DBMS_RANDOM on Oracle.
What DBMS are you using?
精彩评论