日期:2014-05-16  浏览次数:20499 次

随机从数据库取一条记录
(1) ACCESS:
SELECT TOP n * FROM [tablename] {WHERE condition} ORDER BY RND(field_name) {ASC/DESC}


(2) SQL SERVER:
SELECT TOP n * FROM [tablename] {WHERE condition} ORDER BY NEWID() {ASC/DESC}


(3) MYSQL:
SELECT * FROM [tablename] ORDER BY RAND() {ASC/DESC} LIMIT n


(4) ORACLE:
SELECT * FROM (SELECT * FROM [tablename] ORDER BY DBMS_RANDOM.VALUE) temp WHERE rownum <= n
1 楼 JasonLeemz 2011-12-02  
对于数据量很大的表,力不从心啊