While given the publisher name, I wanted to produce a report of books ordered by year and month. For each year and month the report should show bookid, title, total number of orders for the title, total quantity and total selling value (both order value and retail value) while given the book ID
My code :
SELECT
ShopOrder.OrderDate, Book.BookID, Book.title,
COUNT(ShopOrder.ShopOrderID) AS "Total number of order",
SUM (Orderline.Quantity) AS "Total quantity",
Orderline.UnitSellingPrice * Orderline.Quantity AS "Total order value",
Book.Price * OrderLine.Quantity AS "Total retail value"
FROM
ShopOrder, Publisher, Book, Orderline
WHERE
Publisher.name = 'Penguin Books'
AND ShopOrder.ShopOrderID = Orderline.ShopOrderID
AND Book.BookID = Orderline.BookID
AND Publisher.PublisherID = Book.PublisherID
ORDER BY
ShopOrder.OrderDate;
Error:
column "shoporder.orderdate" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: SELECT ShopOrder.OrderDate, Book.BookID, Book.title, COUNT(S... ^ERROR: column "shoporder.orderdate" must appear in the GROUP BY clause or be used in an aggregate function
SQL state: 42803
Character: 8