悠然哈哈哈

导航

sql随机抽取数据

 

 mysql:    select * from tablename order by rand() limit 10

 

sqlserver:    select top 10 * from tablename order by NEWID()

 

 

select ts_name from 表名 as t1 JOIN (RAND()*((select MAX(t_id) FROM 表名)-(select MIN(t_id) from 表名))+(select MIN(t_id) from 表名) as id) as t2
where t1.t_id >=t2.t_id ORDER BY t1.id LIMIT 1

来自:http://bbs.blueidea.com/thread-359132-1-1.html

posted on 2015-10-20 15:43  悠然886  阅读(2598)  评论(0编辑  收藏  举报