| | |
GROUP BY partial field
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2004
Posts: 29
Reputation:
Solved Threads: 0
Hi all.
I have a table with a this records:
I am trying to query the DB to get the total results of activity PER DAY. This is my query (which obviously doesn't work):
Since the date field has also a hour timestamp, I get thousands of results with count 1.
Is there any way to group the results only by the first 10 characters (and omit the time of day)?
Thanks
I have a table with a this records:
MySQL Syntax (Toggle Plain Text)
<!-- Table user_activity --> <user_activity> <id>1</id> <event>LOGIN</event> <username>user@domain.com</username> <domain>domain.com</domain> <remote_address>ip_address</remote_address> <date>2008-05-23 20:19:36</date> <comments></comments> </user_activity>
I am trying to query the DB to get the total results of activity PER DAY. This is my query (which obviously doesn't work):
MySQL Syntax (Toggle Plain Text)
SELECT DATE, COUNT(*) FROM `user_activity` WHERE `event` LIKE "LOGIN" AND `DATE` LIKE "2008-05%" GROUP BY DATE
Since the date field has also a hour timestamp, I get thousands of results with count 1.
Is there any way to group the results only by the first 10 characters (and omit the time of day)?
Thanks
•
•
Join Date: Jan 2009
Posts: 8
Reputation:
Solved Threads: 2
MySQL has a DATE function to extract only the date from a DATETIME field. You should be able to use a query such as the following:
I hope that helps.
sql Syntax (Toggle Plain Text)
SELECT DATE(DATE), count(*) FROM user_activity WHERE event LIKE "LOGIN" GROUP BY DATE(DATE);
I hope that helps.
Last edited by peter_budo; Feb 2nd, 2009 at 7:12 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
![]() |
Other Threads in the MySQL Forum
- Previous Thread: MY SQL reports
- Next Thread: Please suggest: MsAccess to mysql
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop legal license licensing linux maintenance mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns saas select sharepoint simpledb sourcecode spotify sql sugarcrm syntax techsupport thunderbird transparency virtualization





