You need to learn several things about writing SQL queries.
First, always use explicit join
syntax. An easy rule is: Never use commas in the from
clause.
Second, you need to join
the two tables on something. I am guessing a field like PublisherId
, but you might actually know the right field.
Third, in
is much clearer than a sequence of or
clauses.
Four, you cannot include avg()
in a where
clause. That is the purpose of the having
clause.
Five, if you are doing an aggregation expecting multiple result rows, you need a group by
.
SELECT p.NAME, b.CATEGORY, TO_CHAR(AVG(b.RETAIL), '99.99') as "Avg Retail"
FROM BOOKS b JOIN
PUBLISHER p
on b.PublishedId = b.PublisherId
WHERE b.category in ('CHILDREN', 'COMPUTER')
GROUP BY p.NAME, b.CATEGORY
HAVING AVG(b.RETAIL) > 50;