Muiter Posted November 15, 2015 Share Posted November 15, 2015 I am trying to get an query to see the total amount of invoices to paid per week when paying invoice at 60 days after receiving. The query I have is running without problem but the results can not be correct. What might be causing the unexpected result? In the query below I am trying to get the total amount of invoices to be paid in week 52/2015 with the invoice date of 60 days before week 52. When using 30 and 60 days I have the result as below, but the total should be around 364k. (Don't mind the forst row, it's an different query) SELECT SUM(amount) AS amount FROM invoices WHERE date_paid = '0000-00-00' AND WEEK(DATE_ADD(date_recieved, INTERVAL 60 DAY)) = 52 AND YEAR(DATE_ADD(date_recieved, INTERVAL 60 DAY)) = 2015 Link to comment Share on other sites More sharing options...
Ingolme Posted November 15, 2015 Share Posted November 15, 2015 It looks like you're asking it to show you the sum of invoices that were received 60 days before the last week of the year. Is that correct? Link to comment Share on other sites More sharing options...
Muiter Posted November 16, 2015 Author Share Posted November 16, 2015 It looks like you're asking it to show you the sum of invoices that were received 60 days before the last week of the year. Is that correct? Not for the last week but for any week. Week 52 is just an example, it could be any week of the year. Link to comment Share on other sites More sharing options...
Ingolme Posted November 17, 2015 Share Posted November 17, 2015 You should check what values you're actually summing up SELECT date_received, amount FROM invoices WHERE date_paid = '0000-00-00' AND WEEK(DATE_ADD(date_recieved, INTERVAL 60 DAY)) = 52 AND YEAR(DATE_ADD(date_recieved, INTERVAL 60 DAY)) = 2015 From what I can see your query is correct, but I don't know your actual specifications. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now