简体   繁体   中英

How do i write Group By query for datetime field in mysql

I need to group by only date without time from datetime field in table.What can i do friends?

Here My Table field is,

在此输入图像描述

My Mysql query is,

select *,count(ord_number) as ord from tbl_order_details inner join tbl_users on tbl_users.user_id=tbl_order_details.user_id  where 1=1 group by ord_date order by ord asc

You can do it by DATE()

Example -

group by DATE(ord_date)

Try this

select *,count(ord_number) as ord from tbl_order_details inner join tbl_users on tbl_users.user_id=tbl_order_details.user_id  where 1=1 group by DATE(ord_date) order by ord asc

use DATE() function

select *,count(ord_number) as ord from tbl_order_details inner join 
tbl_users on tbl_users.user_id=tbl_order_details.user_id  where 1=1 
group by DATE(ord_date) order by ord asc

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