有一个student表,有学号,姓名,科目,成绩等字段,请写一条sql语句,算出学生的总分数?
展开全部
Mysql 示例:
1. 创建t_student表
CREATE TABLE `t_student` (
`id` int NOT NULL AUTO_INCREMENT , -- 自增ID
`studentID` varchar(20) NULL , -- 学号
`studentName` varchar(20) NULL , -- 姓名
`subject` varchar(50) NULL , -- 科目
`score` double NULL , -- 成绩
PRIMARY KEY (`id`) -- 主键设置
);
2. 填充数据
3. 查询
SELECT
t_student.studentID,
t_student.studentName,
(SELECT b.score FROM t_student AS b WHERE b.studentID = t_student.studentID AND b.`subject` = '语文') AS chineseScore,
(SELECT b.score FROM t_student AS b WHERE b.studentID = t_student.studentID AND b.`subject` = '数学') AS mathematicsScore,
(SELECT b.score FROM t_student AS b WHERE b.studentID = t_student.studentID AND b.`subject` = '英语') AS englishScore,
SUM(t_student.score) AS totalScore
FROM t_student
GROUP BY t_student.studentID
ORDER BY totalScore DESC
展开全部
select 姓名,sum(成绩) as 总分数 from student group by 姓名;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询