SQL - alternate rows from 2 tables
618798Aug 2 2009 — edited Aug 2 2009Hi, 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.