Home  >  Article  >  Database  >  MySQL的一些技巧_MySQL

MySQL的一些技巧_MySQL

WBOY
WBOYOriginal
2016-06-01 13:51:161050browse

使用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

 

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn