Select random number within a specific range in SQL Server

a64a0gku  于 2023-04-04  发布在  SQL Server
关注(0)|答案(1)|浏览(108)

I'd like to select a random decimal between, say, .40 and .60. So .45 or .55 would be desired. .61 not. All ranges would be between 0 and 1.

I have googled and seem to be able to do this with integers using rand()* but can't seem to get it quite right for decimals only.

2q5ifsrm

2q5ifsrm1#

The general form of generating a random number would be min + rand() * (max - min) . So, in your case:

SELECT 0.4 + RAND() * 0.2

相关问题