oracle下可以用函數(shù)decode處理:

創(chuàng)新互聯(lián):公司2013年成立為各行業(yè)開(kāi)拓出企業(yè)自己的“網(wǎng)站建設(shè)”服務(wù),為1000多家公司企業(yè)提供了專(zhuān)業(yè)的成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)和網(wǎng)站推廣服務(wù), 按需網(wǎng)站建設(shè)由設(shè)計(jì)師親自精心設(shè)計(jì),設(shè)計(jì)的效果完全按照客戶的要求,并適當(dāng)?shù)奶岢龊侠淼慕ㄗh,擁有的視覺(jué)效果,策劃師分析客戶的同行競(jìng)爭(zhēng)對(duì)手,根據(jù)客戶的實(shí)際情況給出合理的網(wǎng)站構(gòu)架,制作客戶同行業(yè)具有領(lǐng)先地位的。
select 產(chǎn)品名稱,
sum(decode(季度,'第一季度',銷(xiāo)售額,0)) 第一季度銷(xiāo)售額,
sum(decode(季度,'第二季度',銷(xiāo)售額,0)) 第二季度銷(xiāo)售額,
sum(decode(季度,'第三季度',銷(xiāo)售額,0)) 第三季度銷(xiāo)售額,
sum(decode(季度,'第四季度',銷(xiāo)售額,0)) 第四季度銷(xiāo)售額,
from 表名
group by 產(chǎn)品名稱;
如果“站名”、“條碼”、“時(shí)間”都是一樣的話,可以這么寫(xiě):
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.參數(shù)名 col3, t_temp2.參數(shù)名 col4, t_temp3.參數(shù)名 col5, '時(shí)間' 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.數(shù)值), to_char(t_temp2.數(shù)值), to_char(t_temp3.數(shù)值), to_char(t_temp1.時(shí)間)
from t_temp1, t_temp2, t_temp3
where t_temp1.站名 = t_temp2.站名
and t_temp2.站名 = t_temp3.站名
可用union all來(lái)實(shí)現(xiàn)。
如test表中數(shù)據(jù)如下:
現(xiàn)要將id為3的一條按列顯示,可用如下語(yǔ)句:
select?to_char(id)?str?from?test?where?id=3
union?all
select?name?from?test?where?id=3;
查詢結(jié)果:
行轉(zhuǎn)列的準(zhǔn)則就是通過(guò)主鍵進(jìn)行分組,之后對(duì)行其它字段加上sum()、max()、count()函數(shù),里邊用decode()這類(lèi)函數(shù)進(jìn)行處理,總之分組不要用到他就成。
標(biāo)題名稱:如何行轉(zhuǎn)列oracle,怎樣將列轉(zhuǎn)成行
標(biāo)題網(wǎng)址:http://chinadenli.net/article49/dsisceh.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、手機(jī)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)公司、外貿(mào)建站、營(yíng)銷(xiāo)型網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)