首页 >数据库 >mysql教程 >使用SQL语句随机获取数据

使用SQL语句随机获取数据

WBOY
WBOY原创
2016-06-07 14:53:271520浏览

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