If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MYSQL Query 4 Last month data

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-18-11, 09:42
umermariner umermariner is offline
Registered User
 
Join Date: Mar 2011
Posts: 1
MYSQL Query 4 Last month data

Hello guys,
I think I need a little more help ...
For the query below, I need to get data from last month. Right now, everytime I have to change the query (the dates at the bottom), and then run it to get the right results. I just came across this thread, and it seems like it can be of great help for me. However, I am not able to make it work with the two solutions above. All I want is first date of previous month as the first evttime, and last day of previous month as the higher limit. I know there is a way in MS SQL, getdate(), but it does not work in mysql... and ...

I will appreciate if anyone can help me with that.

select s.sic as "SIC Code", s.cat_name as "SIC Name", count(*) as 'Requests'
from clientservices.p417_caller_revenue_summary r, pmartin.category_names s
where r.evtcode = 4
and r.evtnumber = s.sic
and evttime between unix_timestamp(20110201)
and unix_timestamp(20110301)
group by s.sic

Thanks again.

umermariner
Reply With Quote
  #2 (permalink)  
Old 03-18-11, 11:33
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
What is the datatype for evttime? The UNIX_TIMESTAMP returns an unsigned integer of the number of seconds since 01 Jan 1970. However, its parameter must be a valid date, datetime or timestamp value. Look at STR_TO_DATE function which will allow you to format your date correctly.

So UNIX_TIMESTAMP(STR_TO_DATE('20110201','%Y%d%m')) is most likely what you are looking for.
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
Reply

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On