如何在这种情况下使用RAND功能? [英] How do i use the RAND function for this condition?
本文介绍了如何在这种情况下使用RAND功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个Transact SQL语句,以获取数据库中唯一的三个不同的数字,并四舍五入为三位数.
I need to write a Transact SQL Statement to get three different numbers that are unique in the database rounded upto three digits. How do i do this?
推荐答案
请参阅下面的链接.可能会帮助您找到解决方案.
http://blog.sqlauthority.com/2007 /04/29/sql-server-random-number-generator-script-sql-query/ [
Hi,
See the below link. It might be help you to find your solution.
http://blog.sqlauthority.com/2007/04/29/sql-server-random-number-generator-script-sql-query/[^]
See the Method :1
DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT
---- This will create a random number between 1 and 999
SET @Lower = 1 ---- The lowest random number
SET @Upper = 999 ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
SELECT @Random
Viprat
Viprat
这篇关于如何在这种情况下使用RAND功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文