我有这样的查询
SELECT m.title
FROM Movie AS M
WHERE
(SELECT MAX(r.stars)
FROM rating AS r
WHERE r.mID = M.mID);
我想在结果集中显示MAX(R.stars),我该怎么做?
答案 0 :(得分:3)
试试这个!
SELECT m.title, MAX(r.stars)
FROM Movie AS M
inner join rating AS r
on r.mID = M.mID
group by m.title
或喜欢旧学校方法
SELECT m.title, MAX(r.stars)
FROM Movie AS M,rating AS r
where r.mID = M.mID
group by m.title
答案 1 :(得分:1)
你可以写
SELECT m.title, (SELECT MAX(r.stars) FROM rating AS r WHERE r.mID = M.mID) As MaxStarts
FROM Movie AS M
答案 2 :(得分:1)
如果你真的需要在结果集中显示MAX(R.stars),那么更简单的方法是使用 LEFT JOIN :
SELECT m.Title, MAX(r.stars)
FROM Movie m
LEFT JOIN rating r
ON M.mID = r.mID
无需使用别名。