I started SQL a few weeks ago so I'm fairly new at this. I encountered this exercise in my homework and i was a bit confused or unsure if i did them correctly? Im posting this here to check if i did any mistakes or not. If possible can you tell me if i did them correctly and in case i didnt maybe point out the mistakes and maybe provide some hints on how to fix them?
So this is the exercise
USER (SSN, NameU, SurnameU, City, YearOfBirth, UserType)
MOVIE (CodM, Title, Nation, Language, MovieStudio, Genre)
EVALUATION (SSN, CodM, Evaluation, Date)
a. For each user type, show the average evaluation given to movies produced by "Marvel" (MovieStudio = "Marvel").
SELECT AVG(EVALUATION)
FROM EVAUATION E, USER U, MOVIE M
WHERE E.SSN=U.SSN AND E.CODM=M.CODM AND MOVIESTUDIO='MARVEL'
For the first part i'm a bit confused in the part where it says for each user type . I dont think it is correct but how do i show information about each user type
First, nearly 30 years ago the ANSI-92 standard was adopted to replace using ,
for implicit joins between tables, instead using explicit JOIN
syntax. I strongly recommend avoiding any and all material that attempts to teach you that using ,
is correct; it's not, use JOIN
syntax, it's already close to thirty years old...
Finally, you need to look at using GROUP BY
as part of your aggregation, to get multiple results rather than just one...
SELECT
U.UserType, AVG(EVALUATION)
FROM
USER U
INNER JOIN
EVAUATION E
ON E.SSN=U.SSN
INNER JOIN
MOVIE M
ON E.CODM=M.CODM
WHERE
M.MOVIESTUDIO='MARVEL'
GROUP BY
U.UserType
This will give one row per UserType
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.