oracle 行列轉換 列名數字

來源:互聯網
上載者:User

標籤:str   sele   ref   constrain   杭州   統計   alt   圖片   nvarchar   

oracle 行列轉換列名如果是數字,用雙引號包住  如下:

 

--  建表

create table workinfo
(
wid integer primary key,
sid integer ,
CONSTRAINT sid foreign key(sid) references student(sid),
city nvarchar2(100),-- 就業城市
wage number(10,2),-- 月薪
workdate date,-- 就業時間
eid integer ,
CONSTRAINT eid foreign key(eid) references Emp(eid)-- 介紹人
);
--  假資料

insert into workinfo values(1001,8001,‘上海‘,5000,to_date(‘2009-3-5‘,‘yyyy-MM-dd‘),6005);
insert into workinfo values(1002,8002,‘上海‘,4500,to_date(‘2010-3-5‘,‘yyyy-MM-dd‘),6005);
insert into workinfo values(1003,8005,‘上海‘,5500,to_date(‘2009-3-5‘,‘yyyy-MM-dd‘),6005);
insert into workinfo values(1004,8003,‘杭州‘,4000,to_date(‘2009-12-5‘,‘yyyy-MM-dd‘),6006);
insert into workinfo values(1005,8004,‘杭州‘,4500,to_date(‘2007-12-5‘,‘yyyy-MM-dd‘),6006);
insert into workinfo values(1006,8006,‘南京‘,4000,to_date(‘2009-12-5‘,‘yyyy-MM-dd‘),6006);
insert into workinfo values(1007,8008,‘杭州‘,4000,to_date(‘2009-12-5‘,‘yyyy-MM-dd‘),6006);
insert into workinfo values(1008,8010,‘上海‘,4000,to_date(‘2007-12-5‘,‘yyyy-MM-dd‘),6007);
insert into workinfo values(1009,8007,‘杭州‘,4400,to_date(‘2008-12-5‘,‘yyyy-MM-dd‘),6007);
insert into workinfo values(1010,8009,‘杭州‘,4000,to_date(‘2009-12-5‘,‘yyyy-MM-dd‘),6007);

-- 統計各地區每年就業的人數,顯示如下

select a.city,
              sum(case when a.years=‘2007‘ then a.rs else 0 end) "2007",
              sum(case when a.years=‘2008‘ then a.rs else 0 end) "2008",
              sum(case when a.years=‘2009‘ then a.rs else 0 end) "2008",
              sum(case when a.years=‘2010‘ then a.rs else 0 end) "2009"
from
(
    select city,to_char(workdate,‘yyyy‘) years,count(sid)rs
    from workinfo
    group by city,to_char(workdate,‘yyyy‘)
)a
group by a.city

 

結果

oracle 行列轉換 列名數字

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.