sql如何可以每行都显示不同的随机数?
任意两表abc,和defselectrand()asidfromabcselectd.idfromdef,(selecttop1id,row_number()over(o...
任意两表abc,和def
select rand() as id from abc
select d.id from def,( select top 1 id, row_number() over (order by newid()) as xu from abc) as d
上面两查询到的两个结果为何每行都相同,如何随机行 展开
select rand() as id from abc
select d.id from def,( select top 1 id, row_number() over (order by newid()) as xu from abc) as d
上面两查询到的两个结果为何每行都相同,如何随机行 展开
2个回答
2016-02-16 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
sql中每一行显示随机数根据数据库的不同有不同的写法:
1、在MySQL中写法如下:
SELECT column FROM table
ORDER BY RAND()
LIMIT 1
2、在PostgreSQL中写法如下:
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
3、在Microsoft SQL Server写法如下:
SELECT TOP 1 column FROM table
ORDER BY NEWID()
在IBM DB2中写法如下?:
SELECT column, RAND() as IDX
FROM table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY
Thanks Tim
在Oracle中写法如下:
SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1
1、在MySQL中写法如下:
SELECT column FROM table
ORDER BY RAND()
LIMIT 1
2、在PostgreSQL中写法如下:
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1
3、在Microsoft SQL Server写法如下:
SELECT TOP 1 column FROM table
ORDER BY NEWID()
在IBM DB2中写法如下?:
SELECT column, RAND() as IDX
FROM table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY
Thanks Tim
在Oracle中写法如下:
SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询