I have a table named Inventory
with the following structure:
Location_ID |Item_ID |Stock
1 |A |100
1 |B |500
1 |C |300
2 |A |10
2 |B |20
field location_ID
and item_ID
are composite key. I want to produce the following data from that single table:
Item_ID |Stock_1 |Stock_2
A |100 |10
B |500 |20
C |300 |0
I tried writing several self join queries but it doesn't work. There is also another problem: Item_ID
C does not exist on location_ID
2. How can we put the value '0' on the resulting table if it does not exist? Can someone with brighter mind shed any light?