有顺序的一组数据,如何打乱成无序的,

wuhe 2005-05-21 02:21:58
有顺序的一组数据,如何打乱成无序的,
我记得是通过一个函数就OK了,
可是我把这个函数忘记了

select num from table_num order by + 一个函数


可是我把这个函数忘记了
帮忙一下啊

...全文
127 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
caobin518 2005-05-21
  • 打赏
  • 举报
回复
sql server:

select * from [table] order by newid()

access:

select * from [table] order by rnd(id)


记得给我分
comflyer0590 2005-05-21
  • 打赏
  • 举报
回复
Q. 如何得到随机排序结果?

A. 要得到随机排序的列,或者返回x条随机选择的列,你可以使用随机数。但是RAND函数在一个查询中只能返回一个结果。你可以在NOWID函数返回的列上做ORDER BY。请看示例:

SELECT *
FROM Northwind..Orders
ORDER BY NEWID()

SELECT TOP 10 *
FROM Northwind..Orders
ORDER BY NEWID()

这段话翻译得真是费劲,干脆不管原文,直接意译了。
不过提醒大家注意,这种方法是要对整个表扫描,然后产生一个计算列再排序的,最好不要对大的表作这样的操作,否则会很慢的。


Q. How can I randomly sort query results?

A. To randomly order rows, or to return x number of randomly chosen rows, you can use the RAND function inside the SELECT statement. But the RAND function is resolved only once for the entire query, so every row will get same value. You can use an ORDER BY clause to sort the rows by the result from the NEWID function, as the following code shows:

SELECT *
FROM Northwind..Orders
ORDER BY NEWID()

SELECT TOP 10 *
FROM Northwind..Orders
ORDER BY NEWID()


—SQL Server MVPs


我网上帮你找到的,不过好像在sql语句里直接这样不行,搂主测试好了说明一下怎么用这个函数

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧