1、原始資料(這個資料是下面sql 查出的資料)
月份營業部**
使用者型別
開戶獎調整
提成調整
薪酬支出調集成計
......
......
......
select a.trademonth trademonth,
a.broker_branch brokerbranch,
decode(b.user_type, '3', '2', '5', '2', b.user_type) usertype,
a.margin_trade_tc_adj tc,
a.open_bal_money_adj openbalmoneyadj,
a.broker_branch_sum brokerbranchsum
from rzrq.tb_rzrq_cust_martc_cross a
inner join xc.tb_h_snap_user b on a.user_id = b.user_id
and a.trademonth = b.archive_date
and b.user_type in ('0', '1', '3', '4', '5')
where a.cust_branch <> a.broker_branch
union all
select c.trademonth trademonth,
c.broker_branch brokerbranch,
decode(d.user_type, '3', '2', '5', '2', d.user_type) usertype,
c.normal_trade_tc_adj tc,
0.0000 openbalmoneyadj,
c.broker_branch_sum brokerbranchsum
from rzrq.tb_rzrq_cust_nortc_cross c
inner join xc.tb_h_snap_user d on c.user_id = d.user_id
and c.trademonth = d.archive_date
and d.user_type in ('0', '1', '3', '4', '5')
where c.cust_branch <> c.broker_branch
上面sql作為下面sql的子查詢,進行資料的分組彙總,行轉列
select t.trademonth,
t.brokerbranch,
t.usertype,
sum(case t.usertype when '0' then t.tc else 0 end) 客戶經理提成調整,
sum(case t.usertype when '2' then t.tc else 0 end) 基礎崗提成調整,
sum(case t.usertype when '1' then t.tc else 0 end) 經紀人提成調整,
sum(case t.usertype when '4' then t.tc else 0 end) 業務部提成調整,
sum(openbalmoneyadj) openbalmoneyadjsum,
sum(brokerbranchsum) expadjustsum
from (select a.trademonth trademonth,
a.broker_branch brokerbranch,
decode (b.user_type,'3','2','5','2',b.user_type )usertype,
a.margin_trade_tc_adj tc,
a.open_bal_money_adj openbalmoneyadj,
a.broker_branch_sum brokerbranchsum
from rzrq.tb_rzrq_cust_martc_cross a
inner join xc.tb_h_snap_user b on a.user_id = b.user_id
and a.trademonth = b.archive_date
and b.user_type in ('0','1','3','4','5')
where a.cust_branch <> a.broker_branch
union all
select c.trademonth trademonth,
c.broker_branch brokerbranch,
decode (d.user_type,'3','2','5','2',d.user_type )usertype,
c.normal_trade_tc_adj tc,
0.0000 openbalmoneyadj,
c.broker_branch_sum brokerbranchsum
from rzrq.tb_rzrq_cust_nortc_cross c
inner join xc.tb_h_snap_user d on c.user_id = d.user_id
and c.trademonth = d.archive_date
and d.user_type in ('0','1','3','4','5')
where c.cust_branch <> c.broker_branch) t
group by t.trademonth, t.brokerbranch, t.usertype
分組使用group by ,根據t.trademonth(月份)、t.brokerbranch(營業部號)、t.usertype(使用者型別)分組
行轉列使用case when then 實現
oracle 行轉列,多行轉列
問題描述 應公司要求,設計功能,乙個id,對應不同的值,展示的時候不同的值拼接展示,如何實現 解決思路 1 拼接字串,想到了 oracle function 這樣肯定能實現,但是比較麻煩 2 oracle 自帶的乙個函式 wm concat 函式 非常給力 上 測試表1 create table c...
1 行轉列 資料分組
1 基礎資料 2 要求結果 3 實現 其實你的資料不是這樣,我沒看到,應該有順序的,會更簡單 with ctedata as select 1 as alarmtype,text1 as value union all select 1 as alarmtype,time1 as value uni...
行轉列操作
replace substring,substring index用法例項 源資料 mobile 123342,1232314,1243123,replace substring substring index mobile,a.id char length substring index mobi...