Home >Database >Mysql Tutorial >使用SQL语句随机获取数据

使用SQL语句随机获取数据

WBOY
WBOYOriginal
2016-06-07 14:53:271489browse

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)+"字段)";

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn