SELECt [NAME],
SUM(CASE CLASS WHEN '语文' THEN NUM ELSE 0 END) AS 语文,
SUM(CASE CLASS WHEN '数学' THEN NUM ELSE 0 END) AS 数学,
SUM(CASE CLASS WHEN '英语' THEN NUM ELSE 0 END) AS 英语
FROM SCORE
GROUP BY [NAME]
SELECt [NAME],
MAX(CASE CLASS WHEN '语文' THEN NUM ELSE 0 END) AS 语文,
MAX(CASE CLASS WHEN '数学' THEN NUM ELSE 0 END) AS 数学,
MAX(CASE CLASS WHEN '英语' THEN NUM ELSE 0 END) AS 英语
FROM SCORE
GROUP BY [NAME]
create table w
(
a varchar(10),
b varchar(10),
c int
)
insert w values('语文','张三',80)
insert w values('数学','李思',80)
insert w values('英语','王二',80)
insert w values('语文','周公',80)
select b,'语文'=(select c from w where a='语文' and w.b=k.b),'数学'=(select c from w where a='数学' and w.b=k.b),'英语'=(select c from w where a='英语' and w.b=k.b) from w as k
在查询框中打上
use 该数据库名
select * from score
执行一下就好了,不知道你是否是这个意思,如果解决不了,请追问
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息