Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Query Question: Sum of master and monthly table data

482179Mar 17 2006 — edited Mar 20 2006

Hi All,

I have two tables that store financial data about programs. The PROGRAM table has the following columns (for purposes of this discussion):

ID, INITIAL_BUDGET, COST_CENTER

The PROGRAM_MONTHLY table has the following (abbreviated list of) columns:

ID, PROGRAM_ID (FK to PROGRAM.ID), CURRENT_FORECAST, RECORD_DATE

Every month, a copy of the program_monthly records for last month is made to new records in the PROGRAM_MONTHLY table and we use RECORD_DATE for our filters and comparisons. This way we have historical data, plus current month data that can be updated by our financial systems and program managers.

I am using Application Express and would like to create a dashboard chart that shows the summary of the INITIAL_BUDGET and the CURRENT_FORECAST for a selected month. Obviously, the INITAL_BUDGET doesn't change, but the CURRENT_FORECAST (and similar columns such as the amount committed to purchase orders, which were omitted to simplify the discussion) change monthly.

My goal is to create a chart that can display the initial budget, current forecast, amount committed on purchase orders, etc. for all cost centers, or just one at a time as the user requires, that is filtered by the month of the PROJECT_MONTHLY record. If I can come up with the statement for a view or query, then I can manage the rest.

The required syntax for the chart is "SELECT link, label, value FROM...", where "link" can be NULL, since is it an optional link to another URL. The "label" and "value" portion are the important parts.

For example, I have another chart that shows the project status (which is a Varchar 2 constrained to values such as, Active, On-Hold, Completed, etc.) with the status as the label and the count of the rows as the value. It starts:

select null link, pjm.PROJECT_STATUS label, COUNT(pjm.ID) value FROM ... 

However, I have been unable to come up with a query that generates the desired results for these PROGRAM and PROGRAM_MONTHLY tables. I have played with various types of joins and sub-queries, but my SQL just isn't up to the challenge yet. I realize that I might have to re-work the table structure to accomodate this requirement.

I would greatly appreciate any guidance in approaching this problem.

Many thanks for your time and help,

Petie

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 17 2006
Added on Mar 17 2006
2 comments
283 views