四种数据库随机获取N条数据的方法

1.SQL Server:

SELECT TOP  n  *  FROM  tableName ORDER BY NEWID();

 

2.ORACLE:

SELECT * FROM (SELECT * FROM  tableName ORDER BY DBMS_RANDOM.RANDOM()) WHERE RONUM <= n

 

3.MySQL:

SELECT * FROM  tableName  ORDER BY  RAND() LIMIT n

 

3.Access:

SELECT TOP  n * FROM tableName  ORDER BY rnd([一个自动编号字段])

 

Ps: n 是你要取的条数.O(∩_∩)O~

 

posted @ 2017-09-06 09:54  orac  阅读(1480)  评论(0编辑  收藏  举报