如何随机获得一个表里的数据?先给100分再说!

lastsky 2003-01-14 01:55:19
我要做数据抽样啊,有没例子啊,
多谢
...全文
84 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hjhing 2003-01-14
  • 打赏
  • 举报
回复
頂樓的方法很好
但取得的記錄集合不是按照你表中原來任何一列來排序的

如果你希望按照你表中的某一列再作排序,TRY:

如果你希望這隨機取得的記錄集在

select * from

(SELECT TOP 100 * FROM TABLE ORDER BY NEWID() ) as tableB

order by yourField ---yourField 代表某列名
hjhing 2003-01-14
  • 打赏
  • 举报
回复
值得學習
happydreamer 2003-01-14
  • 打赏
  • 举报
回复
newid()最方便了 呵呵 多试试 肯定是随机的
niuhh 2003-01-14
  • 打赏
  • 举报
回复
先取随机数,然后根据数字到表中取数据
hjhing 2003-01-14
  • 打赏
  • 举报
回复
select identity(int ,1,1) as tid ,*
into #temp
from yourTable

select top 10 * from #temp
where tid % 100 = cast(( rand(checksum(newid()))*100) as int)

select * from #temp

drop table #temp
hjhing 2003-01-14
  • 打赏
  • 举报
回复
----- try:

select identity(int ,1,1) as tid ,*
into #temp
from yourTable

select top 10 * from #temp
where tid % 100 = cast(( rand(checksum(newid()))*100) as int)

drop table #temp



--- 如果你的數據較少,則相應改小上面的100,反之改大點

xpilot 2003-01-14
  • 打赏
  • 举报
回复
这一百分也太好拿了,诶!!!上面已经答对,我就不说了:)
qqqdong 2003-01-14
  • 打赏
  • 举报
回复
全部去出来在随即抽取
alexwoowf 2003-01-14
  • 打赏
  • 举报
回复
SELECT TOP N * FROM TABLE ORDER BY NEWID()

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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