使用RAND()获取随机结果
在ORDER BY语句中可按照如下的随机顺序检索数据行:
mysql> SELECT * FROM tbl_name ORDER BY RAND();
ORDER BY RAND()同 LIMIT 的结合从一组列中选择随机样本很有用:
mysql> SELECT * FROM table1, table2 WHERE a=b AND c -> ORDER BY RAND() LIMIT 1000; GROUP BY列别名 数据表没有day字段(date型),只有ctime字段(datetime型),但需要按天进行汇总统计: mysql> select date(ctime) as day, count(*) from league_apply where ctime >= '2011-02-15' and ctime