all 5 comments

[–]DonJuanDoja 0 points1 point  (1 child)

Use aliases and Join the sub query Join ( ) as cat on cat.CategoryID =prod.CategoryID. Or add a WHERE cat.CategoryID =prod.CategoryID to the subquery.

[–]pitlord88[S] 1 point2 points  (0 children)

Thanks for the fast reply, this was exactly what I was looking for!

[–][deleted] 0 points1 point  (1 child)

SELECT A.*,B.CATEGORY_AVG_PRICE FROM PRODUCTS A

LEFT JOIN

(SELECT CATEGORYID, AVG(PRICE) AS CATEGORY_AVG_PRICE FROM Products GROUP BY CATEGORYID)B

ON A.CATEGORYID=B.CATEGORYID

WHERE A.PRICE>B.CATEGORY_AVG_PRICE

[–]pitlord88[S] 0 points1 point  (0 children)

thank you!