The rollup and cube functions of DB2

Source: Internet
Author: User

The effect of rollup is to count the name of a grouped column after group by.

BankID as the first column

SELECT    Case        -grouping (Branchid) = 0 Then        branchid        ELSE ' subtotal '    END as Branchid,        case When grouping (bankid) = 0 Then        bankid        ELSE ' Total '    END as BankID,    SUM (balance) from    ebanksummwhere< c12/>workdate = ' 20140320 ' GROUP by BankID,        Branchid  with  rollup

Branchid as the first column

SELECT    Case        -grouping (Branchid) = 0 Then        branchid        ELSE ' subtotal '    END as Branchid,    case< C22/>when grouping (BankID) = 0 Then        bankid        ELSE ' Total '    END as BankID,    SUM (balance)    from Ebanksummwhere    workdate = ' 20140321 ' GROUP    by Branchid,    BankID with rollup

The cube function counts all the columns that follow the groupby. The difference between a and rollup is the column to be counted. Rollup counts only one column, and cube counts all columns

SELECT    Case        -grouping (Branchid) = 0 Then        branchid        ELSE ' subtotal '    END as Branchid,        case When grouping (bankid) = 0 Then        bankid        ELSE ' Total '    END as BankID,    SUM (balance) from    ebanksummwhere< c12/>workdate = ' 20140321 ' GROUP by BankID,        Branchid  with  Cube



The rollup and cube functions of DB2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.