简体   繁体   中英

How to group by date not with time

My query return like below

date                    count
November 19,2019,11:58 PM 2
November 19,2019,11:59 PM 2
November 20,2019,12:02 AM 2

Is there any way to do like

November 19,2019 4
November 20,2019 2

Seems your date is not a standard mysql date time format. We need to format it first using str_to_date function.

select cast(str_to_date(dateC, '%M %d,%Y,%h:%i') as date), count(1) from Test
group by cast(str_to_date(dateC, '%M %d,%Y,%h:%i') as date)

see dbfiddle .

follow this query:

在此处输入图片说明

I get this result when I execute the query

select count(*) from listings  group by date(created)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM