這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)如何在Oracle中使用ROLLUP分組函數(shù),文章內(nèi)容豐富且以專(zhuān)業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿(mǎn)足客戶(hù)于互聯(lián)網(wǎng)時(shí)代的路橋網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!環(huán)境準(zhǔn)備
create table dept as select * from scott.dept; create table emp as select * from scott.emp;
業(yè)務(wù)場(chǎng)景:求各部門(mén)的工資總和及其所有部門(mén)的工資總和
這里可以用union來(lái)做,先按部門(mén)統(tǒng)計(jì)工資之和,然后在統(tǒng)計(jì)全部部門(mén)的工資之和
select a.dname, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno group by a.dname union all select null, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno;
上面是用union來(lái)做,然后用rollup來(lái)做,語(yǔ)法更簡(jiǎn)單,而且性能更好
select a.dname, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno group by rollup(a.dname);
業(yè)務(wù)場(chǎng)景:基于上面的統(tǒng)計(jì),再加需求,現(xiàn)在要看看每個(gè)部門(mén)崗位對(duì)應(yīng)的工資之和
select a.dname, b.job, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno group by a.dname, b.job union all//各部門(mén)的工資之和 select a.dname, null, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno group by a.dname union all//所有部門(mén)工資之和 select null, null, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno;
用rollup實(shí)現(xiàn),語(yǔ)法更簡(jiǎn)單
select a.dname, b.job, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno group by rollup(a.dname, b.job);
假如再加個(gè)時(shí)間統(tǒng)計(jì)的,可以用下面sql:
select to_char(b.hiredate, 'yyyy') hiredate, a.dname, b.job, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno group by rollup(to_char(b.hiredate, 'yyyy'), a.dname, b.job);
cube函數(shù)
select a.dname, b.job, sum(b.sal) from scott.dept a, scott.emp b where a.deptno = b.deptno group by cube(a.dname, b.job);
cube
函數(shù)是維度更細(xì)的統(tǒng)計(jì),語(yǔ)法和rollup類(lèi)似
假設(shè)有n個(gè)維度,那么rollup會(huì)有n個(gè)聚合,cube會(huì)有2n個(gè)聚合
rollup統(tǒng)計(jì)列
rollup(a,b) 統(tǒng)計(jì)列包含:(a,b)、(a)、()
rollup(a,b,c) 統(tǒng)計(jì)列包含:(a,b,c)、(a,b)、(a)、()
....
cube統(tǒng)計(jì)列
cube(a,b) 統(tǒng)計(jì)列包含:(a,b)、(a)、(b)、()
cube(a,b,c) 統(tǒng)計(jì)列包含:(a,b,c)、(a,b)、(a,c)、(b,c)、(a)、(b)、(c)、()
上述就是小編為大家分享的如何在Oracle中使用ROLLUP分組函數(shù)了,如果剛好有類(lèi)似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站題目:如何在Oracle中使用ROLLUP分組函數(shù)-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)URL:http://muchs.cn/article38/cspssp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、網(wǎng)站建設(shè)、定制網(wǎng)站、面包屑導(dǎo)航、搜索引擎優(yōu)化、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(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)
猜你還喜歡下面的內(nèi)容