一道sql题目

2019-01-02 23:35发布

4条回答
放我归山
2楼-- · 2019-01-02 23:56

SELECT student,
SUM(CASE course WHEN '语文'THEN score END)AS '语文',
SUM(CASE course WHEN '数学'THEN score END)AS '数学',
SUM(CASE course WHEN '英语'THEN score END)AS '英语'
FROM Score GROUP BY student

查看更多
姐就是有狂的资本
3楼-- · 2019-01-02 23:58

SELECT * FROM aaa /*数据源*/
P
PIVOT
(
SUM(id) FOR
p.bb/*需要行转列的列*/ IN ('语文','数学','英语','生物'/*列的值*/)
) AS T

查看更多
Fickle 薄情
4楼-- · 2019-01-02 23:58

不会.百度:sql行转列.

面试问sql行转列怎么写.我都回:不写sql

查看更多
一纸荒年 Trace。
5楼-- · 2019-01-03 00:08

select student as name,(select b.score from score b where a.student=b.student and b.course='语文') as '语文'
,(select b.score from score b where a.student=b.student and b.course='数学') as '数学'
,(select b.score from score b where a.student=b.student and b.course='英语') as '英语' from score a group by student

查看更多
登录 后发表回答