-- 随机获取 10 条数据
SQL Server:SELECT TOP 10 * FROM T_USER ORDER BY NEWID()
Oracle:SELECT * FROM (SELECT * FROM T_USER ORDER BY DBMS_RANDOM.RANDOM()) WHERE RONUM <= 10
MySQL:SELECT *FROM T_USER ORDER BY RAND()LIMIT 10
access:SELECT TOP 10 * FROM T_USER ORDER BY rnd([一个自动编号字段])这条语句在 Access 中的“查询”中是可以运行并得到随机结果的,但在 asp.net等后台程序代码中却无法得到预期的随机效果。正确的写法如下:以ASP.NET为例:
Random random=newRandom(System.Guid.NewGuid().GetHashCode());intr=random.Next();stringsql="SELECT TOP 10* FROM T_USER ORDER BY RND("+(-r)+"*自动编号字段)"新闻热点
疑难解答