Suppose I have 2 tables T1 and T2 as follows
T1 :
bag_id bag_type capacity
T2 :
item_type item_amount
Each entry in table T1 represents a bag and its capacity, here I have 5 bags. I want to write SQL that selects the elements in table T2 in each bag of the same type, i.e. the result should look like this:
bag_id bag_type capacity allocated_amount
So I find some kind of aggregation function, let it allocate() , which can create the allocated_amount column as above. I have an assumption that if it exists, it can use it as
select t1.bag_id, t1.bag_type, t1.capacity, allocate(t2.item_amount, t1.capacity) over (partition by t1.bag_type order by t1.capacity desc) as allocatd_amount from t1, t2 where t2.item_type = t1.bag_type
My current solution is to use a temporary table and a PL / SQL loop to compute, but I hope I can do this with simple SQL.
sql oracle aggregate-functions oracle11g data-warehouse
asinkxcoswt
source share