码迷,mamicode.com
首页 > 其他好文 > 详细

巧用rand()提取随机行

时间:2016-04-30 01:12:56      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:巧用rand()提取随机行

mysql> select * from category order by rand();


mysql> select * from category order by rand() limit 5 ;

+-------------+-------------+---------------------+

| category_id | name        | last_update         |

+-------------+-------------+---------------------+

|           6 | Documentary | 2006-02-15 04:46:27 |

|           1 | Action      | 2006-02-15 04:46:27 |

|          13 | New         | 2006-02-15 04:46:27 |

|           2 | Animation   | 2006-02-15 04:46:27 |

|          11 | Horror      | 2006-02-15 04:46:27 |

+-------------+-------------+---------------------+

5 rows in set (0.00 sec)


mysql> select * from category order by rand() limit 5 ;

+-------------+-----------+---------------------+

| category_id | name      | last_update         |

+-------------+-----------+---------------------+

|          16 | Travel    | 2006-02-15 04:46:27 |

|          15 | Sports    | 2006-02-15 04:46:27 |

|          13 | New       | 2006-02-15 04:46:27 |

|           2 | Animation | 2006-02-15 04:46:27 |

|           7 | Drama     | 2006-02-15 04:46:27 |

+-------------+-----------+---------------------+

5 rows in set (0.00 sec)


mysql> 







巧用rand()提取随机行

标签:巧用rand()提取随机行

原文地址:http://wangqh.blog.51cto.com/5367393/1769093

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!