当前位置:Gxlcms > mysql > 使用SQL语句随机获取数据

使用SQL语句随机获取数据

时间:2021-07-01 10:21:17 帮助过:45人阅读

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<=50

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

人气教程排行