开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜