Home > Database > Mysql Tutorial > body text

MySQL的一些技巧_MySQL

WBOY
Release: 2016-06-01 13:51:16
Original
1049 people have browsed it

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

 

 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!