Reputation: 41
I currently have a table called Book which has the following fields
BOOK
BOOK_CODE
TITLE
TYPE
There are many options within TYPE, eg SFI,FIC,MYS
I need a query that shows the average price for each option
currently have this but its just showing the average price of all the books:
SELECT AVG(PRICE) FROM BOOK
WHERE TYPE IN ('SFI','MYS','ART','FIC');
Thanks in advance,
Upvotes: 0
Views: 3588
Reputation: 1630
"You can use GROUP BY
to group values from a column, and, if you wish, perform calculations on that column ... " More info: MySQL - GROUP BY Clause
SELECT
Type
,AVG(Price)
FROM Book
GROUP BY Type
Upvotes: 3