Jump to content

Recommended Posts

i need to get the SUM of a field from one table based off a range in another table

 

here's what i think it should should like in the end, but of course it isn't working

 

SELECT SUM(prd.qty) FROM order_products prd
WHERE 
order_list.datemade BETWEEN UNIX_TIMESTAMP('2008-10-01') AND UNIX_TIMESTAMP('2008-10-31')

 

i should mention that the tables look like this

order_list table

id

datemade

etc....

 

order_prods table

id

orderid

prodid

qty

etc...

 

 

 

 

 

i just can't get this query to show up. Any suggestions??

 

Thanks

-C

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/133102-wierd-imo-query-help-me-build-please/
Share on other sites

you need a join there...try this:

 

SELECT SUM(prd.qty) FROM order_products prd
   LEFT JOIN order_list lst ON lst.id = prd.orderid
   WHERE lst.datemade BETWEEN UNIX_TIMESTAMP('2008-10-01') AND UNIX_TIMESTAMP('2008-10-31')

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.