Click here to Skip to main content
15,885,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Trans

(TransID, AcquisitionPrice, AskingPrice, WorkID)

Work

(WorkID, Title, Artist ID)

Artist

(ArtistID, FirstName, LastName)

Question is to list the work ID, title and artist name of all the works of art that sold for more than the average sales price, and the price they sold for.

Hence output should be:

WorkID Title FirstName LastName AcquisitionPrice



I have problem getting this output and calculating the average price. MySQL always says there is something missing.

What I have tried:

SELECT T.WorkID, w.Title, A.LastName, A.FirstName
FROM trans T
JOIN Work w ON T.WorkID = w.WorkID
JOIN Artist A
ON T.acquisitionprice > T.ASKINGPRICE;
(I'm sure the last part is wrong)
Posted
Updated 21-Jun-17 3:04am

1 solution

I'm not an MySQL specialist, but I think it should look like:
SQL
SELECT T.WorkID, w.Title, A.LastName, A.FirstName
FROM trans T
JOIN Work w ON T.WorkID = w.WorkID
JOIN Artist A ON A.ArtistID = w.ArtistID
WHERE T.acquisitionprice > T.ASKINGPRICE
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900