Sample恐怕是不行的,试一下这2个:
select * from (select * from tablename order by sys_guid()) where rownum < N;
select * from (select * from tablename order by dbms_random.value) where rownum< N;
select * from (select * from tablename order by sys_guid()) where rownum < N;
select * from (select * from tablename order by dbms_random.value) where rownum< N;
select * from (select * from tablename order by dbms_random.value) where rownum< N;
这两个看起来可以,但是能解释一下吗?
select * from yourtable order by newid()
这个不行,newid()是什么东西? 能说明一下吗?
这个问题你应该去Oracle板块提问啊1、使用dbms_random程序包, 取出随机数据。先创建序列
create sequence tmp_id increment by 1 start with 1 maxvalue 9999999 nocycle nocache;
2. 然后创建一个临时表tmp_1,记录全部取出来。
create table tmp_1 as select tmp_id.nextval as id,email,mobileno from 表名 where 条件;
找到最大的id号:
select max(id) from tmp_1;
3、设定一个生成随机数的种子
execute dbms_random.seed(12345678);
4、调用随机数生成函数dbms_random.value生成临时表tmp_2,假设随机取200个
create table tmp_2 as select trunc(dbms_random.value(1,5000)) as id from tmp_1 where rownum<201;
说明:dbms_random.value(1,5000)是取1到5000间的随机数,会有小数,
trunc函数对随机数字取整,才能和临时表的整数ID字段相对应。
FROM Northwind..Orders
ORDER BY NEWID()
+ (DATEPART(ss, GETDATE()) * 1000 )
+ DATEPART(ms, GETDATE()) )
select top n * from table order by newid()
的值随你怎么得到,只要小于你的Id最大值就行!!Select top 1 * from table where Id>newId
//随机数的函数我想不起来!!
select top n a.field from table a left join table b on a.id = b.id
group by a.field order by newid()