Home  >  Article  >  Database  >  groupby-mysql Group by 日期。每个时间点数据都要显示出来,没有数据的则为 0 .

groupby-mysql Group by 日期。每个时间点数据都要显示出来,没有数据的则为 0 .

WBOY
WBOYOriginal
2016-06-06 09:40:523012browse

mysqlgroupby

一张表。
数据的主要结构:
id
num
create_time

我现在写的有问题,只能显示有数据的日期。

SELECT DATE_FORMAT(create_time,'%Y-%m-%d') AS day,
(CASE WHEN COUNT(num)='0' THEN 0 ELSE COUNT(num) END) AS counts
FROM infos
WHERE DATE_FORMAT(create_time,'%Y-%m-%d') BETWEEN '2015-05-01' AND '2015-05-30' GROUP BY day

要求:
每个时间点数据都要显示出来,没有数据的则为 0 .

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