mysql 列交換 資料庫行列互換

2021-10-18 10:06:16 字數 1113 閱讀 9355

1:sql server : case group 2:oracle decode group 假設用到的sql語句為: select [姓名],[時代],[金錢] from [test].[dbo].[people] 想要等到如下的結果: 姓名 年輕 中年 老年 張三 1000 5000 800 李四 1200 6000 500 sql server: case [時代] when '年輕'

1:sql server : case group

2:oracle decode group

假設用到的sql語句為:

select [姓名],[時代],[金錢]

from [test].[dbo].[people]

姓名年輕

中年老年

張三李四

sql server:

case  [時代] when '年輕' then [金錢] else 0 end as 年輕

或case when  [時代]= '年輕' then [金錢] else 0 end as 年輕

select [姓名],sum([年輕]) as 年輕,sum([中年]) as 中年,sum([老年]) as 老年 from

(select [姓名],[時代],[金錢],

case  [時代] when '年輕' then [金錢] else 0 end as 年輕,

case  [時代] when '中年' then [金錢] else 0 end as 中年,

case  [時代] when '老年' then [金錢] else 0 end as 老年

from [test].[dbo].[people]) t

group by [姓名]

oracle : decode(時代,'年輕',金錢,0)) 年輕

select [姓名], max(decode([時代],年輕,金錢,0))as 年輕, max(decode([時代],中年,金錢,0))as 中年, max(decode([時代],老年,金錢,0))as 老年 from [test].[dbo].[people] group by 姓名.

mysql 列交換 mysql 行列互換

做工程的人來說,技術通過服務業務來產生價值,所以在提高技術的基礎上,更多的是需要業務知識,更好得體現技術的價值。行轉列 假設你有這樣乙個表,記錄了每個銷售部門,每一天的銷售金額表1,每日各部門銷售金額明細表 use analysis create table tmp department sales...

mysql互換表中兩列資料

mysql互換表中兩列資料 update product set original price price,price original price 上面sql語句顯然不可取 因為先執行original price price original price的值已經更新為price,然後執行price...

mysql互換表中兩列資料

在開發過程中,有時由於業務等需要把乙個表中的兩列資料進行交換。解決方案 使用update命令,這完全得益於mysql sql命令功能的強大支援。中原來資料類似如下 select from product id name original price price 1 雪糕 5.00 3.50 2 鮮花...