请教一句sql
有表类似 (课程分数须累加)
学号 课程 分数
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;
可是这样效率极低。
学号 课程 分数
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;
可是这样效率极低。
...全文
相关推荐
用一句SQL解决SQL中断号问题 推荐
比如,连续生成的编号,由于某种操作(通常为删除)后,产生不连续的编号,我们将这种不连续的编号称为断号。
MySQL用这一句SQL查询出来所有表结构
MySQL用这一句SQL查询出来所有表结构
一句SQL完成动态分级查询
NULL 博文链接:https://powertoolsteam.iteye.com/blog/2370974
只用一句SQL计算名次
只用一句SQL计算名次,允许并列,搜集整理下来,供大家珍藏
sql语句妙用,各种sql语句的详细用法与讲解
sql语句妙用,各种sql语句的详细用法与讲解 ,使得程序运行的更加流畅。主要针对一些高效sql语句的解释。



