Fedora Linux Support Community & Resources Center
  #1  
Old 2nd August 2010, 07:41 AM
Jamwa Offline
Registered User
 
Join Date: Jan 2008
Location: Nairobi Kenya
Posts: 540
linuxfedorafirefox
Help with MySQL Query

I have this query:
Code:
mysql> select distinct date_format(MessageTimeStamp, '%M %e') as Date, count(date(MessageTimeStamp)) as Count from dbCDR group by date(MessageTimeStamp) limit 165, 5;
+----------+-------+
| Date     | Count |
+----------+-------+
| July 29  |   769 |
| July 30  |   271 |
| July 31  |   314 |
| August 1 |   314 |
| August 2 |    65 |
+----------+-------+
5 rows in set (0.04 sec)
Works fine, thanks. However, I want only the first three letters of the month displayed. That is, Jul and Aug instead of the whole name of month. Please help
Reply With Quote
  #2  
Old 2nd August 2010, 10:01 AM
gadgetwiz's Avatar
gadgetwiz Offline
Registered User
 
Join Date: Aug 2006
Posts: 517
linuxfedorafirefox
Re: Help with MySQL Query

Greetings,

SQL supports various string functions, including ..

LEFT(str,len)

Returns the leftmost len characters from the string str, or NULL if any argument is NULL.

http://dev.mysql.com/doc/refman/5.0/...functions.html

You could also make use of the SUBSTRING() function.
__________________
Gimp Chat | Gimp Scripts | Gimp Tutorials

The Linux philosophy is 'Laugh in the face of danger'.
Oops. Wrong One.
'Do it yourself'. Yeah, that's it. - Linus Torvalds
Reply With Quote
  #3  
Old 2nd August 2010, 10:31 AM
Jamwa Offline
Registered User
 
Join Date: Jan 2008
Location: Nairobi Kenya
Posts: 540
linuxfedorafirefox
Re: Help with MySQL Query

Tried all that without success:

mysql> select distinct LEFT(date_format(MessageTimeStamp, '%M %e'), 3) as Date, count(date_format(MessageTimeStamp, '%M %e')) as Count from dbCDR group by date(MessageTimeStamp) limit 165, 5;
Empty set (0.12 sec)

mysql> select distinct substr(date_format(MessageTimeStamp, '%M %e'), 0, 3) as Date, count(date(MessageTimeStamp)) as Count from dbCDR group by date(MessageTimeStamp) limit 159, 7;
Empty set (0.04 sec)

mysql>

---------- Post added at 01:31 AM CDT ---------- Previous post was at 01:15 AM CDT ----------

Got it! date_format(MessageTimeStamp, '%b %e') gives me what I want
Reply With Quote
  #4  
Old 2nd August 2010, 09:53 PM
assen Offline
Registered User
 
Join Date: Oct 2008
Posts: 492
linuxfedorafirefox
Re: Help with MySQL Query

Hi,

In short: use %b instead %M in your original query and forget about substr().

Or, better, before so, check the MySQL manual - at least, the date_format() options: http://dev.mysql.com/doc/refman/5.1/...on_date-format

WWell,
Reply With Quote
Reply

Tags
mysql, query

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql-query-browser in FC5 hiberphoptik Using Fedora 6 17th July 2006 08:43 PM
mysql query browser jet Servers & Networking 0 22nd March 2006 10:49 PM
mysql-query-browser jet Using Fedora 0 20th March 2006 11:44 PM
FC3 and mysql administrator and mysql query browser elmargaro Using Fedora 0 7th November 2005 06:01 PM


Current GMT-time: 03:20 (Friday, 24-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat