最新文章
本栏相关
其他文章
MYSQL随机查询使用方法:
随机获得5条数据(Id不连续)
select *, rand() as random from `table` order by random limit 5
SELECT * FROM `table` WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` ) ORDER BY id LIMIT 5;
SELECT * FROM `table` WHERE id >= (SELECT floor(RAND() * (SELECT MAX(id) FROM `table`))) ORDER BY id LIMIT 5;
SELECT * FROM `table` WHERE id >= (SELECT floor( RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`)) + (SELECT MIN(id) FROM `table`))) ORDER BY id LIMIT 5;
随机获得5条数据(Id连续)
SELECT * FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)) AS id) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT 5;
关于ID连续与不连续的意思
ID连续:即查询出来的数据id是连续的,如:1,2,3,4,5、15,16,17,18,19
Id不连续:即查询出来的数据id是不连续的,如:1,8,9,14,19、12,18,20,28,35
按键盘左右方向键可快速浏览上一篇(←)、下一篇(→)
网站名字: | |
网站地址: | |
验证码: | |
1、您的网站须被百度收录.马上检测是否被百度收录。 2、请在贵站首页把本站的链接加上,谢谢. 获取友情链接代码 3、提出申请成功后,您的链接将在1小时内显示. |
|
申请友情链接 [Enter] |
您的姓名: | |
上一步:鼠标向上滚动/左方向键(←) 下一步或完成:鼠标向下滚动/Tab键/右方向键(→) |
您的电话: | |
您的邮箱: |
信息内容: | |
验证码: |