Home > Database > Mysql Tutorial > body text

MySql按指定天数进行分组数据统计分析 1_MySQL

WBOY
Release: 2016-06-01 13:17:43
Original
1550 people have browsed it

 

这几天,在做数据统计,在对数据库数据进行统计过程中,有个需求就是要按照指定天数进行分组,

 

之前一直没有找到好的方法,就先取出数据,在程序中进行分组。

 

后发现,可以在SQL语句中实现按天数分组。

 

例:

 指定天数11天进行分组统计,例子中加上YEAR(date)* 1000,是为了区分年份

 

 1 SELECT 2     job_id, 3     SUM(`count`)AS total, 4     COUNT(job_id)AS countNum, 5     ( 6         YEAR(date)* 1000 + DAYOFYEAR(date) p 11 7     )AS groupNum 8 FROM 9     job_logs10 WHERE11     job_id = 112 GROUP BY13     groupNum
Copy after login

 

 

 

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!