Home » SQL & PL/SQL » SQL & PL/SQL » Listing individual average price (Oracle SQL)
icon5.gif  Listing individual average price [message #652479] Thu, 09 June 2016 16:43 Go to next message
misy
Messages: 5
Registered: June 2016
Junior Member
I have 3 tables

Book
BookID
SalesPrice
WorkID

Author
AuthorID
Lastname
Firstname

Work
WorkID
Description
AuthorID

Question: How can I list individual author on their average sales price? I'm aint sure how to place the avg code.

My code:
SELECT Lastname,Firstname,Salesprice
FROM Author A JOIN Work W on A.AuthorID = W.WorkID
JOIN Book B on B.WorkID = W.WorkID
WHERE W.WorkID = B.Work ID
Re: Listing individual average price [message #652480 is a reply to message #652479] Thu, 09 June 2016 18:05 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
Use

AVG(Salesprice)

instead of

Salesprice

and remember to GROUP BY any other columns, like Lastname and Firstname, at the end of your code.
Re: Listing individual average price [message #652481 is a reply to message #652480] Thu, 09 June 2016 19:26 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Re: Listing individual average price [message #652506 is a reply to message #652480] Fri, 10 June 2016 12:00 Go to previous message
misy
Messages: 5
Registered: June 2016
Junior Member
Thank you. It works.
Previous Topic: Query Date Ranges with select statement (merged 3)
Next Topic: error 04063 creating view
Goto Forum:
  


Current Time: Tue Apr 23 09:16:28 CDT 2024