Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Group by Clause displaying all lookup values

Muralidhar bAug 19 2012 — edited Aug 19 2012
Hello Friends

I've a simple table with columns namely Date, Reason, Product and Count and the sample data is displayed below.

==========================
Date Reason Product Count
==========================
06/08/2012 Reason1 Home 1
07/08/2012 Reason2 Motor 1
08/08/2012 Reason1 Home 1
09/08/2012 Reason3 Home 2
10/08/2012 Reason1 Home 1
06/08/2012 Reason5 Home 1
===========================

In total I've 5 reason lookup values from Reason1 through to Reason5, but the above table consists of few of them.
I would like to diplay result per day and take an example of 6th August, I want to display below result, i.e. display all 5 reason looksup and assign zero count if there are no records for that day.

=====================================
DATE REASON HOME_COUNT MOTOR_COUNT
=====================================
06/08/2012 Reason1 1 0
06/08/2012 Reason2 0 1
06/08/2012 Reason3 0 0
06/08/2012 Reason4 0 0
06/08/2012 Reason5 1 0
=====================================


If we write group by clause, missing reasons like Reason3 and Reason4 will not be displayed in the result set.
And I've tried to write multiple UNION ALL queries to get the above result which works fine, but if there 100 lookup values, I do not want to write 100 Union queries.
Please let me know if you have any analytical functions to display the end results?

Thanks
Murali.

Edited by: Muralidhar b on Aug 19, 2012 8:17 PM
This post has been answered by Solomon Yakobson on Aug 19 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2012
Added on Aug 19 2012
3 comments
118 views