A particular question that I've been asked to do for my D.A.D class is as follows:
• Write a SQL statement that does the following: • Display the StuId, Movie No, Title, Runtime, Rating code, Rating Short Description, tmdb score for movies that meet any of these criteria: Rating code of M plus a runtime between 160-165 (inclusive) Rating code of G plus a runtime less than 90 Rating code of PG plus a runtime either 120 or 121 Rating code of MA plus a runtime 185 minutes or more • The query must also only include movies that have a tmdb_score more than 6.1. • The list must be in Ascending movie no sequence.
so in response, I've written up this:
SELECT '103040698' as StudID, M.MovieNo, M.Title, M.RunTime, M.RatingCode, M.TMDB_Score, R.SHORTDESC, C.COLOURNAME
FROM Movie0698 M
INNER JOIN RATING0698 R
ON M.RatingCode = R.RatingCode
INNER JOIN COLOURTYPE0698 C
ON M.COLOURCODE = C.COLOURCODE
WHERE (M.RatingCode = 'M' AND M.RunTime BETWEEN 160 AND 165 AND M.TMDB_Score > 6.1)
OR (M.RatingCode = 'G' AND M.RunTime = < 90 AND M.TMDB_Score > 6.1)
OR (M.RatingCode = 'PG' AND M.RunTime BETWEEN 120 AND 121 AND M.TMDB_Score > 6.1)
OR M.RatingCode = 'MA' AND M.RunTime BETWEEN >=185 AND M.TMDB_Score > 6.1)
ORDER BY M.MovieNo ASC;
however, the error message
'OR (M.RatingCode = 'G' AND M.RunTime = < 90 AND M.TMDB_Score > 6.1)
Error at line 8:
ORA-00936: missing expression'
keeps on coming up. with the online program (SQLjunior) pointing out that the '=' is the issue in line 8. I'm unsure where I've gone wrong since I've been using the same formatting for the rest of the question via what's been advised by my tutor and those queries run fine.
The "less than or equal" operator is
<=
, not>=
. I.e., in the condition forM.RunTime
, you should haveM.RunTime <= 90
instead ofM.RunTime =< 90
.