亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Oracle實(shí)現(xiàn)行轉(zhuǎn)換成列的方法

 更新時(shí)間:2016年12月25日 10:34:02   作者:碉堡貓  
這篇文章主要介紹了Oracle實(shí)現(xiàn)行轉(zhuǎn)換成列的方法,實(shí)例分析了Oracle創(chuàng)建及查詢表的相關(guān)操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了Oracle實(shí)現(xiàn)行轉(zhuǎn)換成列的方法。分享給大家供大家參考,具體如下:

把行轉(zhuǎn)成列 把學(xué)生表,成績(jī)表,班級(jí)表,學(xué)科表 合并成一張成績(jī)表效果如下:

創(chuàng)建表

--班級(jí)表
create table CLASS
(
 ID    VARCHAR2(5) not null primary key,
 CLASSNAME VARCHAR2(10)
);
--學(xué)生表
create table STUDENT
(
 ID   VARCHAR2(10) not null primary key,
 NAME  VARCHAR2(10),
 AGE   NUMBER(3),
 CLASSID VARCHAR2(5)
);
--科目表
create table subject(
id varchar2(10) primary key,
subname varchar2(10)
);
--分?jǐn)?shù)表
 create table score(
 sid varchar2(4),
 subid varchar2(10),
 score number(4,1)
);

查詢sql 如下

select s1.name 姓名,
    s1.age 年齡,
    s1.classname 班級(jí),
    score_.sid,
    數(shù)學(xué),
    語(yǔ)文,
    物理,
    化學(xué),
    (數(shù)學(xué) + 語(yǔ)文 + 物理 + 化學(xué)) 總分
 from (select s.sid,
        sum(decode(s.subid, 'SUB001', s.score)) 數(shù)學(xué),
        sum(decode(s.subid, 'SUB002', s.score)) 語(yǔ)文,
        sum(decode(s.subid, 'SUB003', s.score)) 物理,
        sum(decode(s.subid,'SUB004',s.score)) 化學(xué)
     from score s
     group by s.sid) score_
 right join (select st.id, st.name, st.age, c.classname
        from student st, class c
       where c.id = st.classid) s1 on s1.id = score_.sid
 order by 總分;

更多關(guān)于Oracle相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Oracle常用函數(shù)匯總》、《Oracle日期與時(shí)間操作技巧總結(jié)》及《php+Oracle數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)

希望本文所述對(duì)大家Oracle數(shù)據(jù)庫(kù)程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論