當前位置:首頁 » 編程語言 » oracle行轉列sql

oracle行轉列sql

發布時間: 2022-07-12 18:02:41

Ⅰ oracle中如何寫sql實現行列轉換

問下是不是課程只有語文 ,數學,英語沒有別的?
如果是的話那麼:
資料庫是sqlserver的話執行:
select b.stu_name,
max(case a.subject when '語文' then a.grade else '' end) as 語文,
max(case a.subject when '數學' then a.grade else '' end) as 數學,
max(case a.subject when '英語' then a.grade else '' end) as 英語
from stu_grade a,stu_master b
where a.stu_no=b.stu_no
group by b.stu_name
資料庫為oralce的話執行
select b.stu_name,
max(case a.subject when '語文' then to_char(a.grade) else '' end) as 語文,
max(case a.subject when '數學' then to_char(a.grade) else '' end) as 數學,
max(case a.subject when '英語' then to_char(a.grade) else '' end) as 英語
from stu_grade a,stu_master b
where a.stu_no=b.stu_no
group by b.stu_name

Ⅱ oracle 行轉列 動態的考試科目,不用存儲過程,一條sql能寫出來么,怎麼寫!在線等!!

這是我前兩天為另一個哥們寫的
test_bak 的數據
1 a,b,c
2 d,e
轉換後的數據為
1 a
1 b
1 c
2 d
2 e
不知道是不是你想要的,如果是列轉行,oracle 10G以上可用此函數wm_concat
select cc.*,
substr(cc.b,
decode(r_id, 1, 1, instr(cc.b, ',', 1, cc.r_id - 1) + 1),
instr(cc.b, ',', 1, cc.r_id) -
decode(r_id, 1, 1, instr(cc.b, ',', 1, cc.r_id - 1) + 1))
from (select row_number() over(partition by c order by c) r_id,
b || ',' b,
c
from test_bak
connect by c = prior c
AND prior dbms_random.VALUE IS NOT NULL
and level <= length(b) - length(replace(b, ',', '')) + 1) cc;

Ⅲ oracle 行轉列

select
a.DEPARTNAME門店,
b.DEPARTNAME片區,
c.DEPARTNAME區域,
d.DEPARTNAME總公司
from表名a
innerjoin表名bona.PARENTDEPARTMODELID=a.DEPARTMODEID
innerjoin表名conb.PARENTDEPARTMODELID=c.DEPARTMODEID
innerjoin表名donc.PARENTDEPARTMODELID=d.DEPARTMODEID

Ⅳ 【求助】有關oracle 動態行轉列

select*fromcjb.test
createtablecjb.test
(a01varchar2(20),
a02varchar2(20),
a03varchar2(20)

)


selecta.*,a.rowidfromcjb.testa

selecta.a01,
case
whenwm_concat(a.a02||'&'||a.a03)like'%math%'then
(length(wm_concat(a.a02||'&'||a.a03))-
length(replace(wm_concat(a.a02||'&'||a.a03),'math','')))/4else0
endasmath,
case
whenwm_concat(a.a02||'&'||a.a03)like'%chinese%'then
(length(wm_concat(a.a02||'&'||a.a03))-
length(replace(wm_concat(a.a02||'&'||a.a03),'chinese','')))/7else0
endaschinese
fromcjb.testa
groupbya.a01


科目多就往上添加casewhen就可以了

Ⅳ oracle行轉列寫法,麻煩大家幫忙寫個sql,謝謝

可以用wm_concat函數先把數據變成行顯示,然後再通過截取來顯示具體的月份,wm_concat轉換如下

selectcompay_namecn,wm_concat(income)ic

from(selectcompay_name,sum(income)income,substr(time,1,6)time

fromincome

---wheretime>=start_monthandtime<=end_month

groupbycompay_name,substr(time,1,6)

orderbycompay_name,substr(time,1,6))

groupbycompay_name;

Ⅵ ORAClE sql如何實現行轉列

如果「站名」、「條碼」、「時間」都是一樣的話,可以這么寫:

with
t_temp as (select row_number() over (partition by station_name order by param_name asc) id, t.* from t),
t_temp1 as (select * from t_temp where id = 1),
t_temp2 as (select * from t_temp where id = 2),
t_temp3 as (select * from t_temp where id = 3)
select '站名' col1, '條碼' col2, t_temp1.參數名 col3, t_temp2.參數名 col4, t_temp3.參數名 col5, '時間' col6
from t_temp1, t_temp2, t_temp3
where t_temp1.站名 = t_temp2.站名
and t_temp2.站名 = t_temp3.站名
union all
select t_temp1.站名, t_temp1.條碼, to_char(t_temp1.數值), to_char(t_temp2.數值), to_char(t_temp3.數值), to_char(t_temp1.時間)
from t_temp1, t_temp2, t_temp3
where t_temp1.站名 = t_temp2.站名
and t_temp2.站名 = t_temp3.站名

Ⅶ oracle/sql/toad語句怎麼寫,行轉列

select 姓名,地址, wmsys.WM_CONCAT(VALUE1),max(電話) 編號 from 表A GROUP BY 姓名,地址
看max(電話)

Ⅷ oracle的sql語句列轉行

不同人的uuid是不一樣的嗎?


select
(selectzfromtabnameaawherezmc='姓名'andaa.uuid=a.uuid)姓名,
(selectzfromtabnameaawherezmc='年齡'andaa.uuid=a.uuid)年齡,
(selectzfromtabnameaawherezmc='英文名稱'andaa.uuid=a.uuid)英文名稱,
(selectzfromtabnameaawherezmc='性別'andaa.uuid=a.uuid)性別,
(selectzfromtabnameaawherezmc='入職日期'andaa.uuid=a.uuid)入職日期,
(selectzfromtabnameaawherezmc='個人信息'andaa.uuid=a.uuid)個人信息
from(selectdistinctuuidfromtabname)a

Ⅸ oracle 資料庫,寫了一個行轉列的sql,但就是報錯,不知道哪裡錯了。還請大家幫忙看看

Sum VALDATA
沒括弧?SUM(VALDATA)
還有pivot是11g的函數,確保資料庫是11g或以後版本

熱點內容
911標配的有哪些配置 發布:2024-04-30 03:18:38 瀏覽:159
如何訪問阿里雲伺服器多個數據盤 發布:2024-04-30 03:08:45 瀏覽:187
ldd3源碼 發布:2024-04-30 03:07:14 瀏覽:7
phpecho換行 發布:2024-04-30 02:21:51 瀏覽:904
高中ftp 發布:2024-04-30 01:51:48 瀏覽:873
林秋楠手機的密碼是多少 發布:2024-04-30 01:46:31 瀏覽:276
python靜態類方法 發布:2024-04-30 01:30:28 瀏覽:462
zblogphpasp 發布:2024-04-30 01:27:35 瀏覽:137
宏程序自動編程軟體 發布:2024-04-30 01:15:01 瀏覽:417
vs添加編譯選項 發布:2024-04-30 01:06:10 瀏覽:614