mysql随机获取n条数据

做秒杀时,碰到从秒杀商品中随机取商品图的问题,可以用order by rand() limit *随机取出*条记录;

例如:

select gs.original_img from ecs_goods as gs where goods_id in( select goods_id from ecs_flash_sale where 1539323575 >= start_time and 1539323575 <= end_time ) order by rand() limit 1

猜你喜欢

转载自blog.csdn.net/kikyou_csdn/article/details/83027918