摘要:
1、数据量少的时候可以使用sql自带的newid()函数select top 7 from table order by newid()select top 5 a.columName from (select distinct columName from tableName) a order by newid()2、数据量大则不适合用上述方法了,简单算法:统计表里所有的数据N,然后返回一个小于N的随机数,再选择一条ID大于N就行了! SELECT TOP 10 *FROM TB1WHERE (id > CAST(FLOOR(RAND() * (SELECT COUNT(id) FRO 阅读全文