现在的位置: 首页 > 综合 > 正文

SQL case when then else end运用

2012年09月03日 ⁄ 综合 ⁄ 共 338字 ⁄ 字号 评论关闭

表Student:

张三  语文  80

张三  数学  79

张三  英语  96

李四  语文  85

李四  数学  60

李四  英语  94

  转换格式如下:

李四 85 60 94
张三 80 79 96

SQL语句:

select name 姓名,
max(case subject when '语文' then result else 0 end) 语文,
max(case subject when '数学' then result else 0 end) 数学,
max(case subject when '英语' then result else 0 end) 物理
from student
group by name

 

-----------------------

http://www.cnblogs.com/skywang/articles/1423085.html

抱歉!评论已关闭.