| | |
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
Views: 752 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for MySQL
"use" agplv3 alfresco amazon api artisticlicense aws bizspark breathalyzer camparingtocolumns cmg communityjournalism contractors copyright count court crm database developer distinct drupal dui ec2 eliminate email enter enterprise error eudora facebook form foss gartner government gpl greenit groklaw hiring hyperic innerjoins insert ip joebrockmeier join journalism keyword keywords kickfire laptop law legal license licensing linux maintenance managing mariadb matchingcolumns micromanage microsoft mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlquery news open-xchange opendatabasealliance opengovernment opensource oracle pdf penelope php priceupdating query referencedesign remove reorderingcolumns results resultset saas search select sharepoint simpledb sourcecode sql statement sugarcrm syntax thunderbird transparency update virtualization





