1👍
✅
Try the below query
SELECT p.PRODUCT_CODE, SUM(case when p.PRODUCT_ID=od.PRODUCT_ID and od.ORDER_ID=o.ORDER_ID then od.TOTAL_AMT_PER_ITEM else 0 end)
as TOTAL_AMT_PER_ITEM
FROM [ORDER] o
INNER JOIN ORDER_DETAILS od
ON o.ORDER_ID = od.ORDER_ID
INNER JOIN PRODUCT p
ON od.PRODUCT_ID=p.PRODUCT_ID
GROUP BY p.PRODUCT_CODE
You missed an alias name for the sum of case expression, You can try running your original query and can see if result set has the column name what you are expecting to make sure.
Source:stackexchange.com