Oracle中SQL查詢縱錶轉橫表
縱向表
縱轉橫
SQL實現
select max(decode(trim(t.codename), '個單', trim(t.codename), null)) A,
max(decode(trim(t.codename), '團單', trim(t.codename), null)) B,
max(decode(trim(t.codename), '團單個單', trim(t.codename), null)) C,
max(decode(trim(t.codename), '匯交件個單', trim(t.codename), null)) D,
max(decode(trim(t.codename), '養老金', trim(t.codename), null)) E
from t_codedef t
where t.codetype = '001';
Oracle中使用分組聚合函數查詢縱錶轉橫表
Oracle10g
數據表:
要求,顯示code唯一性,並大小寫字符顯示爲同一行。
select code , wm_concat(name) from decode group by code ;
查詢結果:
select code , replace(wm_concat(name),',','-') from decode group by code ;
查詢結果: