行转列问题

select 姓名 as 姓名 ,
  max(case 课程 when '语文' then 分数 else 0 end) 语文,
  max(case 课程 when '数学' then 分数 else 0 end) 数学,
  max(case 课程 when '物理' then 分数 else 0 end) 物理
from tb
group by 姓名

如果A大于B 取 B 否则取A 如果B大于C 取 B 否则取 C
select (case when A>B then A else B end) as 'A’ , (case when B>C then B else C end) as 'B' from Person;

---更新表table中的字段ID,更新规则:ID小于2的更新为0,大于5的更新为5,
--其他的更新为3(一条SQL语句实现)
update dbo.ceshis set name=case when Id<2 then 0 when Id>5 then 5 else 3 end

原文地址:https://www.cnblogs.com/yinchuan/p/3570346.html