Solved

oracle rollup query

Posted on 2016-11-03
3
36 Views
Last Modified: 2016-11-04
Hi ,

My question might sound easy , but I want to understand why oracle is not generating a grand total when I fire the below query

Select department_id , job_id , count(*)
from employees
group by department_id,rollup(department_id, job_id)

I get the grandtotal with rollup , if i fire the below query

Select department_id , job_id , count(*)
from employees
group by rollup(department_id, job_id)

Any help is really appreciated. The above queries are firedin HR schema.
0
Comment
Question by:sam_2012
3 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 41872834
rollup()   applies the aggregates within the grouping.

In the first query you have grouped within department, so the rollup only generates counts within department.  The total within a department across all departments is still just the department.

That's why each department has 2 rows with a null job_id.   The second row is the grand total.

In the second query, you don't have a grouping other than the rollup itself so it generates totals on departments and across all departments.
1
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 41873693
well, in query1 you first group by department_id
that has priority over the rollup

that's why you don't get a total
0
 

Author Closing Comment

by:sam_2012
ID: 41874822
awesome
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now