mysql中随机取出几条数据

 SELECT t1.id,title,extName,cover,url
 FROM shop_articles AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM shop_articles)-(SELECT MIN(id) FROM shop_articles))+(SELECT MIN(id) FROM shop_articles)) AS id) AS t2 
 WHERE t1.id >= t2.id and type=_type
 ORDER BY t1.id LIMIT _num;

 

posted @ 2015-04-29 13:04  逍遥帝君  阅读(378)  评论(0编辑  收藏  举报