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 > This weeks invoiced qty

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-20-06, 15:12
bayder bayder is offline
Registered User
 
Join Date: Feb 2004
Posts: 18
Question This weeks invoiced qty

I am trying to find out the qty of items invoiced this week.

I can get the last 7 days with the following query:

SELECT SUM(quantity) from invoices WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= inv_date

My problem is that on Monday morning I need the qty to start at 0 again but the above will include part of last week.

Can anyone help with this?

Thanks...
Reply With Quote
  #2 (permalink)  
Old 01-21-06, 04:37
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,258
depending on what front end you are using you may be able to do what you want more esaily.

But in MySQL there are several date functions that may help
dayofWeek() will return todays day Sunday=1, Saturday=7
weekday()
date_add()
date_sub()
-if you are using version 5 then your could write sproc to handle it otherwise you will have to write a fairly convluted SQL statement
HTH
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 01-21-06, 10:34
jfulton jfulton is offline
Registered User
 
Join Date: Apr 2005
Location: Baltimore, MD
Posts: 297
Sounds like you want to group by the week of the year?

Check out the date and time functions. You may want to look at WEEK() and WEEKOFYEAR().
Reply With Quote
  #4 (permalink)  
Old 01-21-06, 13:02
bayder bayder is offline
Registered User
 
Join Date: Feb 2004
Posts: 18
Darn it, I always forget to post the version number that I am using

Thanks for the pointers. I think I may have a solution in mind, I just have to play with it a little
Reply With Quote
  #5 (permalink)  
Old 01-21-06, 16:28
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,258
Quote:
Originally Posted by bayder
...Darn it, I always forget to post the version number that I am using ...
if thats a problem just create a signature admitting to what versions of what you are using - it removes some of the doubt on trying to help.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
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