如何用sql语句随机抽取n条不重复的数据记录?

allboy 2005-06-13 07:32:46
如题
...全文
421 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
八哥 2005-07-31
  • 打赏
  • 举报
回复
select top 10 * from tablename order by newid()
cdsun 2005-07-31
  • 打赏
  • 举报
回复
select top 10 * from tablename order by newid()

这个只能在sql server当中用
Stony1980 2005-06-15
  • 打赏
  • 举报
回复
select distinct 字段号 from table就可以了
南山明月 2005-06-15
  • 打赏
  • 举报
回复
你们都答错了,跑题了,不是吗,楼主
你是想实现类是抽奖的程序吧,是随机抽取n条不重复的数据记录,这个记录就是
Recordset(1) 不能出现两次,是吧,但具体Recordset(1)和Recordset(2)是不是
一样就不管理它了,是吗?是我再答,可能我理解错了也不定
cxianfa 2005-06-14
  • 打赏
  • 举报
回复
select distinct 字段号 from table就可以了
yemj 2005-06-14
  • 打赏
  • 举报
回复
SELECT DISTINCT ColumnName FROM TableName
yemj 2005-06-14
  • 打赏
  • 举报
回复
select语句中加上distinct关键字
haipingma 2005-06-13
  • 打赏
  • 举报
回复
declare @n int
set @n=5
declare @strSql nvarchar(1000)
set @strSql='select top '+cast(@n as varchar) + ' * from kc_bank order by newid()'
exec(@strSql)
haipingma 2005-06-13
  • 打赏
  • 举报
回复
select top 10 * from tablename order by newid()

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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