104

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.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Zack Burt
  • 8,257
  • 10
  • 53
  • 81
  • 2
    Try: `select * from follow_queue group by cast(follow_date as date)` first. – NawaMan Sep 23 '09 at 22:16
  • 3
    you don't need to cast, just use the DATE() function – markus Sep 23 '09 at 22:56
  • Doesn't the DATE() function cast the datetime to a string? Sure, it works for grouping by date, but I think NawaMan's answer is more correct based on the phrasing of the question – DJDave Feb 09 '16 at 13:54

1 Answers1

204

Use DATE() function:

select * from follow_queue group by DATE(follow_date)
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
ChssPly76
  • 99,456
  • 24
  • 206
  • 195