I have this table: (supply table: how many products in storages)
Storage_id product_id amount
1 1000 55
1 1005 1
...
29 1000 3
29 1421 21
29 1566 0
30 1259 921
I should write a query to have this result:
storage_id product_id amount
1 1000 55
2 1000 61
...
30 1000 10
total_except_storage_30 1000 1505
1 1001 1
2 1001 50
...
30 1001 56
total_except_storage_30 1001 1251
...
"Total_except_storage_30" has the total of every product in storages except storage number 30. For example first "total_except_storage_30" is for product_id 1000 in all storages except storage_id 30 and the second is for product_id 1001.
*** I am not allowed to use "Union".
I tried to use full outer join but this did not work and the result is without "total_except_storage_30":
Select t.Storage_id, t.product_id, t.amount
from myTable t full outer join
(
select 'total_except_storage_30' as storage_id, product_id, sum(amount)
from myTable
group by product_id
) total
on t.storage_id = total.storage_id