Skip to content
Advertisement

How to aggregate with join

I am very new to SQL and I was wondering if someone could help me find the quantity on hand (dqty-sqty) for each iname? This is what I’ve been trying to do so far but the total quantity that I get is wrong:

Thanks so much!

enter image description here

Advertisement

Answer

you need to take the sum of the delivered and sold items individually as JOINs will not work directly on tables as there is many to many relationship between two tables.

Try this:

I have used LEFT JOIN in case the item is not sold.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement