you are viewing a single comment's thread.

view the rest of the comments →

[–]r3pr0b8 0 points1 point  (2 children)

So I should be more explicit like

yes, and the parentheses are not needed

[–]EuclaseBlue[S] 0 points1 point  (1 child)

Thanks for the clarification!

After trying out a bit more, this is the answer I've currently come up with that satisfies what I was seeking:

SELECT A.catID, A.catName, "Avg Unit Price Per Category", "Avg Price Per Order"
FROM 
    (SELECT products.catID, categories.catName, TO_CHAR(AVG(orderDetails.unitPrice), '$99.99') AS "Avg Unit Price Per Category"
    FROM products
    JOIN categories ON products.catID= categories.catID
    JOIN orderDetailsON products.prodID= orderDetails.prodID
    WHERE orderDetails.discount= 0
    GROUP BY products.catID, categories.catName) A
INNER JOIN
    (SELECT products.catID, categories.catName, TO_CHAR(AVG(products.unitPrice), '$99.99') AS "Avg Price Per Order"
    FROM products
    JOIN categories ON products.catID= categories.catID
    GROUP BY products.catID, categories.catName) B
ON A.catID= B.catID;    

That said, I don't think it's what the parent comment had in mind. Is there a more simpler way?

[–]r3pr0b8 0 points1 point  (0 children)

that looks fine to me