从MySQL随机选取数据方案
方案一: 利用mysql+应用实现
// 1,,计算总记录数
SELECT COUNT(*) AS `offset` FROM `sd_crowd_label_enum`
// 2, 利用应用计算随机开始角标
index = rand(xx)
// 3,批量获取
SELECT * FROM `sd_crowd_label_enum` LIMIT index, 10
方案二: mysql实现(前提是该表有自增id)
-- 子查询计算随机开始角标
SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `sd_crowd_label_enum`
-- 批量获取
SELECT * FROM `sd_crowd_label_enum` where id > (SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `sd_crowd_label_enum`) LIMIT 0, 100
方案三:mysql实现(利用数据更新字段实现)
SELECT * FROM `sd_crowd_label_enum` order by gmt_create LIMIT 0, 100
每次操作完,数据更新字段时间都会更新
参考:
相关推荐
苏康申 2020-11-13
vitasfly 2020-11-12
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11
世樹 2020-11-11