Sorry for the vague subject line, but I dont know the terms to describe this problem. As I've begun trying to use this data for reporting, I've been running into a few 'issues' as the users did not go for a standardized format. Anyways, I am working on a report and having trouble getting exactly the data I want to come across.
First a glimpse of the data I am working with:
Master Job, Sub Job, Contract_Amount, Billed_JTD, Total_Contract
1001, 1001, 12,000,000, 3,450,000, 12,000,000
2113, 2113, 4,500,000, 0, 0
2113, 2113-02, 750,000, 0, 750,000
2117, 2117, 0, 0, 0
2117, 2117-03, 250,000, 0, 0
2117, 2117-07, 9,250,000, 0, 0
Basically, there are cases where there is just 1 row, other times the job is split into subjobs. Lastly, there can be the case where master = subjob does not hold the main contract amount. In the case of 2113, there is a pre- construction deal to prep the site before the actual contract is signed.
Now, for my report there is a set of criteria that causes the job to appear in 1 of 2 views. First view is Current work. Here I Sum up the columns like Contract Amount, Billed etc and determine if they should show up with the following Having Clause
Having
Sum(Total_Contract) > 1,000,000 and (SUM(Total_Contract) – SUM(Billed_JTD)) > 100
As you can see, job 1001 would show up on this project, which is perfect!
Next up, Future work:
This view is almost identical, except that we want to show
Having
Sum(Total_Contract) > 1,000,000 and (SUM(Total_Contract) – SUM(Billed_JTD)) > 100 AND Sum(Total_Contract) = 0
Here job 2117 would show up which is correct. As you may see, Job 2113 is the problem as it does not fit either set. Its total contract is < 1 million, so its not on Current, and its total contract <> 0 so it is not on the Future.
This job should actually be show on the future report. I would like to use the Having criteria not on the SUM but just on the row with the largest Contract Amount. How would I craft a query to grab this info job by job and return the summed info only if the max contract row meets the criteria?
Thanks!
First a glimpse of the data I am working with:
Master Job, Sub Job, Contract_Amount, Billed_JTD, Total_Contract
1001, 1001, 12,000,000, 3,450,000, 12,000,000
2113, 2113, 4,500,000, 0, 0
2113, 2113-02, 750,000, 0, 750,000
2117, 2117, 0, 0, 0
2117, 2117-03, 250,000, 0, 0
2117, 2117-07, 9,250,000, 0, 0
Basically, there are cases where there is just 1 row, other times the job is split into subjobs. Lastly, there can be the case where master = subjob does not hold the main contract amount. In the case of 2113, there is a pre- construction deal to prep the site before the actual contract is signed.
Now, for my report there is a set of criteria that causes the job to appear in 1 of 2 views. First view is Current work. Here I Sum up the columns like Contract Amount, Billed etc and determine if they should show up with the following Having Clause
Having
Sum(Total_Contract) > 1,000,000 and (SUM(Total_Contract) – SUM(Billed_JTD)) > 100
As you can see, job 1001 would show up on this project, which is perfect!
Next up, Future work:
This view is almost identical, except that we want to show
Having
Sum(Total_Contract) > 1,000,000 and (SUM(Total_Contract) – SUM(Billed_JTD)) > 100 AND Sum(Total_Contract) = 0
Here job 2117 would show up which is correct. As you may see, Job 2113 is the problem as it does not fit either set. Its total contract is < 1 million, so its not on Current, and its total contract <> 0 so it is not on the Future.
This job should actually be show on the future report. I would like to use the Having criteria not on the SUM but just on the row with the largest Contract Amount. How would I craft a query to grab this info job by job and return the summed info only if the max contract row meets the criteria?
Thanks!