Question
September 17, 2007 at 01:48 PM
v_legaspi

oracle: how to “easily” divide two resultsets?

by v_legaspi . Updated 19 years, 1 month ago

Hi,

I have the following two SQLs and their resultsets (table names have been changed):

PRODUCTS:
select sum(q1), sum(q2), sum(q3), sum(q4)
from product_history
where technology_type = ‘Stocked’
and year = :year;

Q1 Q2 Q3 Q4
———- ———- ———- ———-
40 60 35 0

STAFF:
select sum(q1_fte) q1, sum(q2_fte) q2, sum(q3_fte) q3, sum(q4_fte) q4
from staff_history
where stock_designator = ‘Stocked’
and year = :year;

Q1 Q2 Q3 Q4
———- ———- ———- ———-
40 41 40 0

I want to calculate how much staff are spent per product per quarter. Is there an “easy” way to divide each quarter column by its corresponding column in the other resultset?

For example, can I get products.q1 / staff.q1 through products.q4 / staff.q4 in one SQL statement? Something like:
products.resultset
/
staff.resultset

Has someone done this before? Suggestions greatly appreciated.

Thanks in advance!

This discussion is locked

All Comments