Groupby extended grouping function of Oracle

Source: Internet
Author: User
Oracle groupby extended grouping function test learning process is as follows: --- rollup: take each department as the reference object, details of employee salaries under each department and summary selectt.de

Oracle group by extended grouping function test learning process is as follows: --- rollup: take each department as the reference object, details of employees' salaries under each department and summary of select t.de

Group by function of Oracle

The test process is as follows :-
-- Rollup: Details and summary of employees' salaries in each department for reference.
Select t. dept_id, t. dept_name, sum (t. salary)
From qcfang. test1 t
Group by rollup (t. dept_id, t. dept_name)


-- Cube: Cross-report with the largest amount of information, including summary and details
Select t. dept_id, t. dept_name, sum (t. salary)
From qcfang. test1 t
Group by cube (t. dept_id, t. dept_name)


-- Rollup cancels the final total. In fact, it filters out records whose dept_id is null.
Select t. dept_id, t. dept_name, sum (t. salary)
From qcfang. test1 t
Group by t. dept_id, rollup (t. dept_name)
Order by t. dept_id


-- The cube cancels the total. In fact, it filters out records whose dept_id is null.
Select t. dept_id, t. dept_name, sum (t. salary)
From qcfang. test1 t
Group by t. dept_id, cube (t. dept_name)


-- Grouping settings: a summary of different values in each dimension, which is equivalent to multiple union all
Select t. dept_id, t. dept_name, sum (t. salary)
From qcfang. test1 t
Group by grouping sets (t. dept_id, t. dept_name)


-- Use the grouping function to find out the sum: flag = 1 is the sum.
Select t. dept_id, t. dept_name, sum (t. salary), grouping (t. dept_name) flag
From qcfang. test1 t
Group by rollup (t. dept_id, t. dept_name)
Order by t. dept_id


-- Filter groups using the grouping Function
Select t. dept_id, t. dept_name, sum (t. salary), grouping (t. dept_name) flag
From qcfang. test1 t
Group by rollup (t. dept_id, t. dept_name)
Having grouping (t. dept_name) = 0


-- Sort by grouping_id
Select t. dept_id, t. dept_name, sum (t. salary), grouping (t. dept_name) flag
From qcfang. test1 t
Group by rollup (t. dept_id, t. dept_name)
Order by grouping_id (t. dept_id, t. dept_name), t. dept_id

Recommended reading:

Oracle Lpad Functions

Oracle Regular Expression Functions

Oracle DB Group functions

Oracle DB uses conversion functions and conditional expressions

Learning window functions over () in Oracle

,

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.