行转列问题
select 姓名 as 姓名 ,
? max(case 課程 when '語文' then 分?jǐn)?shù) else 0 end) 語文,
? max(case 課程 when '數(shù)學(xué)' then 分?jǐn)?shù) else 0 end) 數(shù)學(xué),
? max(case 課程 when '物理' then 分?jǐn)?shù) 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,更新規(guī)則:ID小于2的更新為0,大于5的更新為5,
--其他的更新為3(一條SQL語句實現(xiàn))
update dbo.ceshis set name=case when Id<2 then 0 when Id>5 then 5 else 3 end
轉(zhuǎn)載于:https://www.cnblogs.com/yinchuan/p/3570346.html
總結(jié)
- 上一篇: mysql 语法积累
- 下一篇: PI-安装SoapUI on Windo