Oracle ROLLUP和CUBE 用法

來源:互聯網
上載者:User

CUBE和ROLLUP  ROLLUP是Oracle8i以來一個新的SQL關鍵字,9i ,-11G不新鮮了,它是對GROUP BY子句的擴充,允許在SELECT語句中計算不同層次的小計。

CUBE是對GROUP BY子句的另外一  種擴充,它允許計算所有小計可能的組合,用來產生各種匯總報表。

以下介紹他們的用法

select B,c,D from Atest group by rollup(B,C,D);

相當於

select B,c,D from Atest group by B,C,D;

union all

select B,c,null from Atest group by B,C

union all

select B,null,null from Atest group by B

select B,c from Atest group by cube(B,C);

將所有 (B,C)組合的子集group by合并

相當於

select B,c from Atest group by B,C

union all

select B,null from Atest group by B

union all

select null,c from Atest group by c

union all

select null,null from Atest group by null

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.