Hi can someone help me with this question please. i spent ages trying to figure out what am doing wrong but no luck
Tables
- Publisher(publisherName,location, noOftitles)
- Author(name,location)
- Book(title,isbn,cost,authorName,publisherName)
Question
Write a SQL command to display for each publisher with more than one author, the publisher’s name, the publisher’s location and the average cost of the books that the publisher sells.
Code:
SELECT Book.publishername, location, avg(cost)
FROM Publisher
, Book
WHERE Publisher.publisherName = Book.publisherName
GROUP
BY publisherName
HAVING COUNT (DISTINCT authorname) >1
error
ORA-00918: column ambiguously defined
Right Answer:
SELECT Publisher.publisherName, Publisher.location, avg(cost)
FROM Publisher, Book
WHERE Publisher.publisherName = Book.publisherName
GROUP BY Publisher.PublisherName, Publisher.Location
HAVING COUNT (DISTINCT authorname) >1;