views:

864

answers:

2

My query is this. I have a bunch of entries and i want to group them by date. But instead of having date in my database, I have a datetime field. What do I do?

select * from follow_queue group by follow_date cast follow_date as date

That's not working.

Thanks!

+4  A: 

Use DATE() function:

select * from follow_queue group by DATE(follow_date)
ChssPly76
How do I get the "count" for entries per date? Just do select field,count(*) from follow_queue group by date(follow_date)?
Zachary Burt
Yup. `select DATE(follow_date), count(*) from follow_queue group by 1`
ChssPly76
Group by 1? What does that mean?
Zachary Burt
It means group by first column in the select list, in this case `DATE(follow_date)`. You can do that with `ORDER BY` as well - `ORDER BY 1, 2`, for example
ChssPly76
A: 

It's fine. But, if the date format in mysql database saved as y/m/d format, then how can CAST function will be used.

Zamshed Farhan