Solved

oracle rollup query

Posted on 2016-11-03
3
87 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 74

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 38

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

623 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