(图一)
(图二)
这是在 SQL 里实现透视(pivot),通用的是用 case 表达式。
select name,
max(case when subject = '语文' then score else null end) as 语文, // 这里需要使用聚合函数,max、min 什么的都行
max(case when subject = '数学' then score else null end) as 数学,
max(case when subject = '英语' then score else null end) as 英语
from tblName
group by name
https://blog.csdn.net/beernum/article/details/83378768
select name,(select score from 表 t1 where t1.name=t.name and subject='语文') as 语文,
(select score from 表 t2 where t2.name=t.name and subject='数学') as '数学',
(select score from 表 t3 where t3.name=t.name and subject='英语') as '英语'
from 表 t group by name;
SELECT NAME,
MAX(DECODE(SUBJECT,'语文',SCORE)),
MAX(DECODE(SUBJECT,'数学',SCORE)),
MAX(DECODE(SUBJECT,'英语',SCORE))
FROM TABLE1
GROUP BY NAME