如何实现随机每隔5条就提取出一条数据!
解决方案 »
- select 查询时 字段列表用 * 还是 写上 要查询的字段
- mysql数据库优化问题
- 安装phpwind 7.0 UTF8 后不能注册,提示SQL syntax错误
- mysql5.0下查询数据时碰到的乱码问题
- 如果将2004-04-12 12:20:12转换成日期型的数据呢
- 关于时间戳的一个问题
- Windows下MySQL有没有可视操作?
- 关于管理使用mysql的可视化工具,请推荐几个,多谢了
- MySQL: Unknown character set: 'utf8mb4怎么解决
- Mysql 1067 无法启动
- ERROR 1172 (42000): Result consisted of more than one row?
- MYSQL问题请教
+----+------+
| id | c1 |
+----+------+
| 1 | A1 |
| 2 | A2 |
| 3 | A3 |
| 4 | A4 |
| 5 | A5 |
| 6 | A6 |
| 7 | A7 |
| 8 | A8 |
| 9 | A9 |
| 10 | A10 |
| 11 | A11 |
| 12 | A12 |
| 13 | A13 |
| 14 | A14 |
| 15 | A15 |
| 16 | A16 |
| 17 | A17 |
| 18 | A18 |
| 19 | A19 |
| 20 | A20 |
| 21 | A21 |
| 22 | A22 |
| 23 | A23 |
| 24 | A24 |
| 25 | A25 |
| 26 | A26 |
| 27 | A27 |
| 28 | A28 |
| 29 | A29 |
| 30 | A30 |
| 31 | A31 |
+----+------+
31 rows in set (0.00 sec)mysql> select table1.*
-> from table1,(select 1+FLOOR(rand()*5)+((id-1) div 5)*5 as tid
-> from table1
-> where id%5=0) t
-> where table1.id=t.tid;
+----+------+
| id | c1 |
+----+------+
| 3 | A3 |
| 6 | A6 |
| 13 | A13 |
| 17 | A17 |
| 25 | A25 |
| 29 | A29 |
+----+------+
6 rows in set (0.00 sec)mysql>
(select *,ceiling(id/5) as newid,
ceiling(rand()),floor(id-rand()*5+1)
as newid1
from lsb1 where id mod 5=0) b
on a.id=b.newid1