群中看到别人发的一个面试题,=。=,怎么查询的呢。
select name, sum(case when Course='Chinese' then Score end) as Chinese,
sum(case when type='Math' then Score end) as Math,
sum(case when type='English' then Score end) as English
from table1
group by name4 回答970 阅读
4 回答889 阅读
2 回答843 阅读
2 回答627 阅读
2 回答679 阅读
1 回答648 阅读
586 阅读
题图是Chinase,按这个来。
Course确定情况下:
CASE实现:
IF实现:
Course不确定,使用动态: