随机取表中记录

Oracle:

 

select * from
(

select
 t1.*
from
  table_name t1 ,
  (select round(DBMS_RANDOM.VALUE() * (select max(id) from tb_eshop_order_base)) id from table_name) t2
where t1.id >= t2.id
order by
t1.id
)
where rownum <= 1

mysql:

 

select
    t1.*
from table_name as t1 join (select round(rand() * (select max(id) from table_name)) as id) as t2
where t1.id >= t2.id
order by t1.id asc limit 1

你可能感兴趣的:(记录)