Groupby-mysqlGroupby date. Data is displayed at each time point. if no data exists, the value 0 is displayed.

Source: Internet
Author: User
A table. The main structure of the data: idnumcreate_time I am writing a problem, only display the date of the data. SELECTDATE_FORMAT (create_time, & #39; % Y-% m-% d & #39;) ASday, (CASEWHENCOUNT (num) & #39; 0 & #39; THEN0ELSECOUNT (num) END) AScountsFROMinfosWHEREDATE_FORMAT (create_time, & #39; % Y-% m-% d & #39;) BETW mysqlgroupby

A table.
Data structure:
Id
Num
Create_time

I have a problem with the current writing. only the date with data can be displayed.

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 '2017-05-01' AND '2017-05-30 'group by day

Requirements:
Data is displayed at each time point. if no data exists, the value 0 is displayed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.