Advanced query problem (Group by,count ...)

Advanced query problem (Group by,count ...)

  
Dear All,

My problem

table 1 {STOCK}
Table 2 {STOCK_OWNER}  


I would like to get a result like this

Owner, quantity

Outsystems, 0
Microsoft , 2
Oracle ,3

Where Owner is {STOCK_OWNER}.NAME and Quantity a SUM from {STOCK}.Quantity.  I thought i could solve this with a left outer join. Left outer join means table left always shows up. 


Below my query:
  

SELECT {STOCK_OWNER}.[Id],{STOCK_OWNER}.[Name],SUM({STOCK}.[Quanity])
FROM {STOCK_OWNER} LEFT OUTER JOIN {STOCK}
ON {STOCK_OWNER}.[Id]={STOCK}.[STOCK_OWNER_ID]
WHERE {STOCK}.[Part_Type_Id]=@PartTypeID

GROUP BY {STOCK_OWNER}.[Id],{STOCK_OWNER}.[Name]

Thank you in advance!
 

a sub query helped me out!

 

SELECT A.[Id],A.[Name], SUM(B.[Quanity])
FROM {STOCK_OWNER} A LEFT OUTER JOIN (SELECT [STOCK_OWNER_ID],[Quanity] FROM {STOCK}  WHERE {STOCK}.[Part_Type_Id]=@PartTypeID ) B
ON A.[Id]=B.[STOCK_OWNER_ID]
GROUP BY A.[Id],A.[Name]