惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
Jina AI
Jina AI
雷峰网
雷峰网
月光博客
月光博客
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
美团技术团队
C
CXSECURITY Database RSS Feed - CXSecurity.com
小众软件
小众软件
Security Latest
Security Latest
Microsoft Azure Blog
Microsoft Azure Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
A
Arctic Wolf
Latest news
Latest news
Attack and Defense Labs
Attack and Defense Labs
I
Intezer
F
Fortinet All Blogs
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
Webroot Blog
Webroot Blog
S
Secure Thoughts
Help Net Security
Help Net Security
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
V
Visual Studio Blog
P
Proofpoint News Feed
博客园 - 【当耐特】
P
Privacy International News Feed
V
Vulnerabilities – Threatpost
Stack Overflow Blog
Stack Overflow Blog
Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
Hacker News: Ask HN
Hacker News: Ask HN
L
LINUX DO - 最新话题
H
Help Net Security
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
T
Tailwind CSS Blog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tenable Blog
Cloudbric
Cloudbric
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog

博客园 - dnddn

axios输出图片显示 ElementUI时间选择控件提交的时间为UTC时间 pypi清华镜像 JS引用传值问题 通过Access-Control-Allow-Origin解决跨域问题 解决mac下mysql libssl.1.0.0.dylib报错问题 Google App Engine初探 SQL2005的阀值设定 移动硬盘识别不了的问题 网球术语英汉对照 【丰富词汇量,喜欢网球的路过说声。。】 几个小问题 - dnddn - 博客园 SilverLight,有多少人关心呢? be my friend 检讨 简单的就是最好的 这个五一 紧张非封闭式开发中 静静的看twittervision SQL Server 2005 数据类型
MSSQL中的随机函数
dnddn · 2007-05-26 · via 博客园 - dnddn

随机函数:rand()
在查询分析器中执行:select rand(),可以看到结果会是类似于这样的随机小数:0.36361513486289558,像这样的小数在实际应用中用得不多,一般要取随机数都会取随机整数。那就看下面的两种随机取整数的方法:

1、
A:select  floor(rand()*N)  ---生成的数是这样的:12.0
B:select cast( floor(rand()*N) as int)  ---生成的数是这样的:12

2、
A:select ceiling(rand() * N)  ---生成的数是这样的:12.0
B:select cast(ceiling(rand() * N) as int)  ---生成的数是这样的:12

    其中里面的N是一个你指定的整数,如100,可以看出,两种方法的A方法是带有.0这个的小数的,而B方法就是真正的整数了。
    大致一看,这两种方法没什么区别,真的没区别?其实是有一点的,那就是他们的生成随机数的范围:
方法1的数字范围:0至N-1之间,如cast( floor(rand()*100) as int)就会生成0至99之间任一整数
方法2的数字范围:1至N之间,如cast(ceiling(rand() * 100) as int)就会生成1至100之间任一整数
对于这个区别,看SQL的联机帮助就知了:
------------------------------------------------------------------------------------

比较 CEILING 和 FLOOR

CEILING 函数返回大于或等于所给数字表达式的最小整数。FLOOR 函数返回小于或等于所给数字表达式的最大整数。例如,对于数字表达式 12.9273,CEILING 将返回 13,FLOOR 将返回 12。FLOOR 和 CEILING 返回值的数据类型都与输入的数字表达式的数据类型相同。
----------------------------------------------------------------------------------
现在,各位就可以根据自己需要使用这两种方法来取得随机数了^_^

另外,还要提示一下各位菜鸟,关于随机取得表中任意N条记录的方法,很简单,就用newid():
select top N *  from table_name order by newid() ----N是一个你指定的整数,表是取得记录的条数.