Oracle行列轉換sql
發布時間: 2024-04-13 11:48:19
⑴ sql棰橈細璇風敤涓涓錛圤racle錛塖QL瑙e喅琛屽垪杞鎹㈤棶棰
yclfwm 緇欐垜鍔犲垎鍝︼紒
select student,nvl(sum(yuwen),-1) as yuwen,nvl(sum(shuxue),-1) as shuxue,nvl(sum(wuli),-1) as wuli
from ( select student,
case when cource='yuwen' then mark else null end as yuwen,
case when cource='shuxue' then mark else null end as shuxue,
case when cource='wuli' then mark else null end as wuli
from bob_cj )
group by student
order by student
⑵ sql怎樣將行的值變為列,,,,
方法/步驟
首先我們建立一張表,名為RToC,各個欄位的設計如下圖,分別是name,course,score,表示姓名,成績與分數,如圖所示。
通過以上幾個步驟,我們就可以輕松的實現行列轉換了。同樣,我們如果要把列轉換成行, 應該怎麼做呢?同樣我們可以採用unpivot函數輕松實現。
熱點內容