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!

SQL - alternate rows from 2 tables

618798Aug 2 2009 — edited Aug 2 2009
Hi, not sure how to best put this, but I have 2 tables for a Sales database. One is for our Sales Agents Actual sales (Agent_Sales, Product, Jul, Aug, Sep, Oct....) showing the actual sales by agent. PK is composite Agent_Sales and Product. The other table is similar but for the Targets (Agent_Target , Product, Jul, Aug, Sep, Oct....) with the PK again being composite Agent_Target and Product.

What I would like to do is get a listing for each agent in a table listing the actuals on the first line, then Targets on the second. Furthermore the 3rd line will be the variance between actuals and target and 4th line a percentage to target.

I would like the output to look like this:

Jul Aug Sep Oct
Agent_Sales 8 9 10 8
Agent_Target 9 8 8 9
Variance -1 1 2 -1
Percent 0.89 1.12 1.25 0.89


Thanks in advance.
This post has been answered by Frank Kulash on Aug 2 2009
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2009
Added on Aug 2 2009
2 comments
739 views