首頁 >資料庫 >mysql教程 >使用SQL语句随机获取数据

使用SQL语句随机获取数据

WBOY
WBOY原創
2016-06-07 14:53:271499瀏覽

SQL Server-- SELECT TOP 50 * FROM TAB_USERS ORDER BY NEWID(); ORACLE-- SELECT * FROM (SELECT * FROM TAB_USERS ORDER BY DBMS_RANDOM.RANDOM()) WHERE RONUM=50 MYSQL-- SELECT * FROM TAB_USERS ORDER BY RAND() LIMIT 50 { ACCESS-- SELECT TOP 50

  SQL Server--> SELECT TOP 50 * FROM TAB_USERS ORDER BY NEWID();

  ORACLE--> SELECT * FROM (SELECT * FROM TAB_USERS ORDER BY DBMS_RANDOM.RANDOM()) WHERE RONUM

  MYSQL--> SELECT * FROM TAB_USERS ORDER BY RAND() LIMIT 50

  {

  ACCESS--> SELECT TOP 50 * FROM TAB_USERS ORDER BY RND([字段])

  这条语句在ACCESS中的查询结果是正确的,但在ASP.NET等后台代码要写成如下:

  Random random=new Random(System.Guid.NewGuid().GetHashCode());

  int val=random.Next();

  string sql="SELECT TOP 50 * FROM TAB_USERS ORDER BY RND("+(-r)+"字段)";

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn