MySQL語句如何實現(xiàn)從數(shù)據(jù)庫表中查詢隨機(jī)數(shù)據(jù)的記錄
1. Oracle,隨機(jī)查詢20條
select * from
(
select * from 表名
order by dbms_random.value
)
where rownum <= 20;
2.MS SQL Server,隨機(jī)查詢20條
select top 20 * from 表名order by newid()
3.My SQL:,隨機(jī)查詢20條
select * from 表名 order by rand() limit 20
SELECT * FROM phpcms_video where catid=17 order by rand()
獲取到的隨機(jī)結(jié)果如下圖所示:
1. Oracle,隨機(jī)查詢20條
select * from
(
select * from 表名
order by dbms_random.value
)
where rownum <= 20;
2.MS SQL Server,隨機(jī)查詢20條
select top 20 * from 表名order by newid()
3.My SQL:,隨機(jī)查詢20條
select * from 表名 order by rand() limit 20
SELECT * FROM phpcms_video where catid=17 order by rand()
獲取到的隨機(jī)結(jié)果如下圖所示: