Jump to content

Tricky 'GROUP BY' MySQL question


webbgroup

Recommended Posts

How would you group by dates in a table where the date shows up like this: \"2003-01-15 13:05\"

 

I already tried something like this without much success.

 

select time as TIME, count(*) as posts from table group by time REGEXP \"2003-01-%\";

 

Any suggestions??

Link to comment
Share on other sites




mysql> SELECT DATE_FORMAT(\'1997-10-04 22:23:00\', \'%Y-%m-%d\');

+------------------------------------------------+

| DATE_FORMAT(\'1997-10-04 22:23:00\', \'%Y-%m-%d\') |

+------------------------------------------------+

| 1997-10-04                                     |

+------------------------------------------------+

1 row in set (0.00 sec)



mysql> 



 

Use the date_format consistently throughout the query.

 

I think you should read the mysql manual about date functions:

 

http://www.mysql.com/doc/en/Date_and_time_..._functions.html

 

P., denmark

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.