oracle 將查詢結果縱向橫向顯示。

2021-07-10 03:42:54 字數 643 閱讀 5143

使用max(decode())函式可以將將查詢結果縱向橫向顯示;

例如:表 dict

編號(lxbh)             型別名稱(lxmc)

101 變壓器

102 斷路器

103 電磁是電壓互感器

104 電容式電壓互感器

顯示
變壓器 斷路器 電磁是電壓互感器 電容式電壓互感器
101    102    103               104
select  max(decode(d.lxmc,' 變壓器',y.lxbh,null)) 變壓器

,max(decode(d.lxmc,' 斷路器',y.lxbh,null)) 斷路器

,max(decode(d.lxmc,' 電磁是電壓互感器',y.lxbh,null)) 電磁是電壓互感器

,max(decode(d.lxmc,' 電容式電壓互感器',y.lxbh,null)) 電容式電壓互感器

from dict y



MSSQL SQL 查詢結果的縱向變橫向排列

create table booklibary 圖書館 varchar 10 科目 varchar 10 數量 int insert into booklibary select a 語文 5 union all select b 數學 6 union all select c 英語 3 union...

MSSQL將查詢結果橫向顯示

表1 year month,amount 200801 5 200802 6 200803 9 200802 4 顯示結果 year 01 02 03 tot 2008 5 0 0 5 2008 0 10 0 10 2008 0 0 9 9 2008 0 0 0 24 可能多個年,多個月create...

oracle 橫向列變為縱向列

很多業務需求儲存資料的時候都採取key value的形式,展示時則需要key1,key2,key3.展示 效果如下 sql語句如下 select round sum case when data item code backn52 then data item value else 0 end 2 ...