双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

请教一句sql

Jill_Yao Jill_Yao 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
有表类似 (课程分数须累加)
学号 课程 分数
1 A 90
2 B 30
.
.
.

需要形成统计表格如下
学号 课程A 课程B 课程C 课程D
1 90 50 60 70
2 80 55 78 34
.
.
.

怎么写效率高呢

我只想出
select id,
(select sum(fenshu) from table where class='A' and b where b.id table.id) A,
(select sum(fenshu) from table where class='B' and b where b.id table.id) B,
(select sum(fenshu) from table where class='C' and b where b.id table.id) C
from table;
可是这样效率极低。




...全文
评论 8
收藏 已收藏
分享
返回顶部
Jill_Yao
MS-SQL Server 34,876 成员 254,635 内容