第十题 我写的是select student.sid,student.sname,max(score)
from sc right join student on student.sid=sc.sid
group by student.sid;
但是查询结果还多了一了一行最大值为null的结果,怎么查可以没有这个呢
select student.sid,student.sname,max(score)
from sc right join student on student.sid=sc.sid
group by student.sid having max(score) is not null
有帮助的话,请点采纳该答案~
可以使用COALESCE函数将NULL替换为一个默认值,例如0或空字符串。修改后的SQL语句如下:
SELECT student.sid, student.sname, COALESCE(MAX(score), 0)
FROM student LEFT JOIN sc
ON student.sid = sc.sid
GROUP BY student.sid;
在这里,我们将RIGHT JOIN更改为LEFT JOIN,并使用COALESCE函数将score的最大值替换为0,如果没有匹配的值。这将确保查询结果中没有NULL值。
不知道你这个问题是否已经解决, 如果还没有解决的话: