Home > Database > Mysql Tutorial > mysql 将字段time按天/月/年分组_MySQL

mysql 将字段time按天/月/年分组_MySQL

WBOY
Release: 2016-06-01 13:05:25
Original
1092 people have browsed it

假设表中有一个字段time,格式为Unix时间戳,现需要按照该字段统计每天的记录数。

方法:

利用convert函数convert(char(10),time,120) as time,然后group by time即可。

原理:convert函数将时间戳转换成ODBC标准时间(120参数指定),然后取前十位,则刚好得到完整日期(不含时分秒),再分组即可。

按月,按年分组方法一样,只需要修改convert()方法第一个参数的长度。

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