SQL 查询语句优化:显示课程名称而不是课程号
原始 SQL 查询语句:
select Course.c_id 课程id, c_name 课程号, max(s_score) 最高分, min(s_score) 最低分, round(avg(s_score),2) 平均分, count(s_score) from Score ,Course where Score.c_id=Course.c_id group by Score.c_id;
问题:
虽然语法上没有问题,但在查询结果中,'c_name' 显示的是课程号,而不是课程名称。
解决方案:
为了显示课程名称,需要修改查询语句,将 'c_name' 列替换为实际存储课程名称的列名。
示例:
假设课程名称存储在 'c_name' 列,则修改后的查询语句为:
select Course.c_id 课程id, Course.c_name 课程名称, max(s_score) 最高分, min(s_score) 最低分, round(avg(s_score),2) 平均分, count(s_score) from Score ,Course where Score.c_id=Course.c_id group by Score.c_id;
注意:
请根据实际数据库结构和列名进行相应的调整。
原文地址: https://www.cveoy.top/t/topic/mY28 著作权归作者所有。请勿转载和采集!