Group by Clause displaying all lookup values

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

If you followed relational design, you have reason lookup table. If you do not have it you should create one. Also, date is reserved word and count is a keyword, so do not use them as column names. Then use outer join:
SQL> create table tbl as
  2  select to_date('06/08/2012','dd/mm/yyyy') dt,'Reason1' reason,'Home' product,1 qty from dual union all
  3  select to_date('07/08/2012','dd/mm/yyyy'),'Reason2','Motor',1 from dual union all
  4  select to_date('08/08/2012','dd/mm/yyyy'),'Reason1','Home',1 from dual union all
  5  select to_date('09/08/2012','dd/mm/yyyy'),'Reason3','Home',2 from dual union all
  6  select to_date('10/08/2012','dd/mm/yyyy'),'Reason1','Home',1 from dual union all
  7  select to_date('06/08/2012','dd/mm/yyyy'),'Reason5','Home',1 from dual
  8  /
Table created.
SQL> create table reason_list as
  2  select  'Reason' || level reason from dual connect by level <= 5
  3  /
Table created.
SQL> select  d.dt,
  2          r.reason,
  3          nvl(
  4              sum(
  5                  case product
  6                    when 'Home' then qty
  7                  end
  8                 ),
  9              0
10             ) home_qty,
11          nvl(
12              sum(
13                  case product
14                    when 'Motor' then qty
15                  end
16                 ),
17              0
18             ) motor_qty
19    from      (
20               select  min_dt + level - 1 dt
21                 from  (
22                        select  min(dt) min_dt,
23                                max(dt) max_dt
24                          from  tbl
25                       )
26                 connect by level <= max_dt - min_dt + 1
27              ) d
28          cross join
29              reason_list r
30          left join
31              tbl t
32            on (
33                    t.dt = d.dt
34                and
35                    t.reason = r.reason
36               )
37    group by d.dt,
38             r.reason
39    order by d.dt,
40             r.reason
41  /
DT        REASON                                           HOME_QTY  MOTOR_QTY
06-AUG-12 Reason1                                                 1          0
06-AUG-12 Reason2                                                 0          0
06-AUG-12 Reason3                                                 0          0
06-AUG-12 Reason4                                                 0          0
06-AUG-12 Reason5                                                 1          0
07-AUG-12 Reason1                                                 0          0
07-AUG-12 Reason2                                                 0          1
07-AUG-12 Reason3                                                 0          0
07-AUG-12 Reason4                                                 0          0
07-AUG-12 Reason5                                                 0          0
08-AUG-12 Reason1                                                 1          0
DT        REASON                                           HOME_QTY  MOTOR_QTY
08-AUG-12 Reason2                                                 0          0
08-AUG-12 Reason3                                                 0          0
08-AUG-12 Reason4                                                 0          0
08-AUG-12 Reason5                                                 0          0
09-AUG-12 Reason1                                                 0          0
09-AUG-12 Reason2                                                 0          0
09-AUG-12 Reason3                                                 2          0
09-AUG-12 Reason4                                                 0          0
09-AUG-12 Reason5                                                 0          0
10-AUG-12 Reason1                                                 1          0
10-AUG-12 Reason2                                                 0          0
DT        REASON                                           HOME_QTY  MOTOR_QTY
10-AUG-12 Reason3                                                 0          0
10-AUG-12 Reason4                                                 0          0
10-AUG-12 Reason5                                                 0          0
25 rows selected.
SQL> SY.

Similar Messages

  • How to display all distinct values without duplicates.

    Hi Pros,
          I want to present a values list in dashboard, but this list have much duplicates, so when dispalying, I want to display all distinct values without duplicates.

    Hi,
    You can avoid the duplicates from the source side or use a filtered row option in the component.
    Arun

  • Parameter List displaying all the values on Parameter form

    Dear All...If I uncheck the "Restrict List to predetermined values" option, then report parameter form displays all the values on web parameter form instead of displaying those values in the List Item. Is it the Default behaviour of Oracle Reports 10g or Can I control it anyway because if I've 1000 entries in a list, then displaying all those values openly on the form is an ugly thing and it increases the size of parameter form very much.

    Hello,
    A solution is provided in the Note :
    Note.465886.1 How to Implement an Alternate Solution to Unrestricted List Of Values (LOV) in Parameter Form on the Web:
    regards

  • OADefaultListBean to display all the values

    Hello,
    Using OADefaultListBean, i was able to display all the selected values using the below logic but how to get list of all the values in the OADefaultListBean instead of just the selected ones?
    OADefaultListBean list =
    (OADefaultListBean)webBean.findChildRecursive("positionsList");
    String name = list.getName();
    String[] selectedValues = pageContext.getParameterValues(name);
    In the above code, pageContext.getParameterValue(name) gives the list of all the selected values but how to get the list of all the values?
    Thanks
    KK

    Basically my whole point in doing this is to give an option of ALL in the OADefaultListBean so that just by selecting the ALL in the list, it should technically select all the values.
    Thanks a lot in advance for your help

  • Problem with Crystal Reports not displaying all parameter values

    Hello,
    A co-worker of mine is developing a report in Crystal version 11.5.8.826.  One of the requirements from his user is that they would like to select from a list of users for applicable criteria to appear in the report.  He created a parameter with a dynamic list of values, entered prompt group text, selected "existing" as the data source (and chose the corresponding field from the table).  This dropped the UserID field into the "value" field in the table and linked the table to the parameter.  We selected "allow multiple values" as "true" and "allow discrete values" as "true". 
    Here is the problem.  When Crystal prompts us to select the parameters, it doesn't show all of the applicable list of users (it shows 8 out of 12 users).  When we run the query in a standalone sql generating tool (Toad or Golden), we see the full list of users.  Crystal Reports appears to be filtering the selection list of users for some unknown reason.  We have tried changing most every option that we could find within the parameter, but no luck. 
    The problem definitely appears to lie within the parameter- if we run the report without the parameter, we see the full list of users.  Once we add the parameter and attempt to select one or many users, the problem appears.
    Any thoughts?  What am I missing?  Any help is appreciated.
    thanks,
    Noel

    I'll answer my own question in case somebody is curious or happens to find this message via google or another search engine.  See this link.  You need to set your upper threshold within your Registry Editor.
    http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=8029

  • KE30 report: Graphic not displaying all charcateristic values

    Hi Experts,
    I created a report in KE30, and in classic view, when I select 1 characteristic and 1 value field to view in a 3D graphic, I don't see all the characteristic values that were displayed in the report. I have 73 characteristics but only 30 are being displayed in the graphic.
    Do you know if this is a system limitation? Because I didn't find a way to expand it.
    Kind Regards
    Mayumi Blak

    display too wierd..post it in clearly...

  • Can chart "across" axis display all dimension values?

    I have a chart that has Race going across the bottom, and I'm displaying the number of students at a given school in a given grade for each race (African-American, Asian, White, etc...) We have a total of 7 race categories.
    In a particular classroom, let's say that there are no Asian students and no Native American students. The vertical bar chart automatically displays only the 5 other race categories for which there are students.
    Is it possible to instruct the chart to always include all 7 races across the chart, with a null (zero height) bar for those races without student counts?

    If you don't have a row for particular races, then use combine with similar request to get those.
    assuming your main request have race, Measure then combine with similar request race,column with code 0.
    1 st request race,measure
    2 nd reqeust race,0
    now if you see the output you will see all the 7 races from second request with 0 values. now create the chart. chart will do aggregation of values from 2 requests. Now you will see all the 7 entries. Let me know if it is not clear.
    - Madan

  • Display all quantity values, buy sales want highest value in same report

    Hi
    I have slares do num , and item and qty and sales cal month
    if i execute based on month i need get top sales value ( i mean higherst values for that report) and quantity need show all values?
    if i apply condition top 1 for sales its effecting qty also?
    ple let me know what is solution for this, ?

    Hi Suneel,
                     Try with this.....
    Keyfigure  -
    > properties----->calculate single value as---> maximum.
    check here....
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/1f/25883ce5bd7b1de10000000a114084/content.htm
    Hope this will help you.
    Thanks,
    Vijay.

  • Display all cell values in calculation?

    Is it possible to replace cell references with actual cell values in a calculation (not a formula)?
    For example, how do I replace the cell references below with the actual numbers in those references?
    =(A2-B2)/(A3-B3)*(F3+E3)/(F2+E2)

    The short answer is "no". The long answer is "with an excruciating expression you can do it, but who would want to, and why?
    Here's an example:
    Cell A5 has the first portion of your expression shown the way I think you are requesting. I tired of writing the expression and I'm not sure it's what you want anyway. If you look in the Formula Bar you can see how complex the expression it, just to do that first part.
    Jerry

  • Displaying All Values from a Multiple Value Parameter

    Hi,
    Using XI, I have a parameter field that allows the user to enter multiple values Eg. 01, 02, 13, 14.  I want to create a formula to display all the values the user has selected. 
    Is there a way to do this? 
    Thanks,
    Brian

    join({?Parameter},",")
    creates a string with the items in your parameter separated by commas

  • -- SQL -- GROUP BY clause: non-aggregate fields mandate

    Hello,
    I was studying Databases, (particularly the retrieval of the data), and found something interesting.
    While using an Aggregate Function in the SELECT clause, it is mandatory to have all the non-aggregate fields in the SELECT clause to be there in the GROUP BY clause.
    For example,
    SELECT dept_no, SUM(salary)
    FROM employee
    GROUP BY dept_no;
    The above SQL works fine.
    But, what if the user misses the dept_no in the GROUP BY clause or he/she misses the GROUP BY clause itself?
    Certainly, it is an error.
    Why is this error not handled by the database. I mean, the database should be smart/intelligent enough to add the GROUP BY clause by itself. So suppose, if I miss out the GROUP BY clause or miss a non-aggregate field from the SELECT clause when I am having at least one aggregate function on a field with at least one non-aggregated field in the SELECT clause, the database should check the GROUP BY clause at time of compilation and add the mandate missed out fields in the GROUP BY clause.
    Example,
    SQL1:_
    SELECT dept_no, SUM(salary)
    FROM employee
    GROUP BY dept_no;
    SQL2:_
    SELECT dept_no, SUM(salary)
    FROM employee;
    Here, the SQL1 and SQL2, both should give me same outputs without an error.
    I am unable to understand why is this not handled?

    Hi,
    998478 wrote:
    ... If we mix aggregate and non-aggregate values then there must be a GROUP BY clause containing all the non-aggregate values. Why is this not handled by the database/compiler itself? It IS handled by the compiler itself. The compiler handles it by raising an error. The compiler has no way of knowing whether you want to remove something from the SELECT clause, or to add something to the GROUP BY clause, or not to use aggregate functions, or to use more aggregate functions, or some combination of the above. If the compiler re-wrote your code, and did any of these things automatically, it would be wrong more often than it was right, and you would (rightly) be complaining about its behavior.
    For example, this is clearly wrong:
    SELECT    deptno
    ,       job
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;What is the right way to fix it?
    <h3>1. Remove something from the SELECT clause</h3>
    SELECT    deptno
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;<h3>2. Add something to the GROUP BY clause</h3>
    SELECT    deptno
    ,       job
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ,         job
    ;<h3>3. Not use aggregate functions</h3>
    SELECT    deptno
    ,       job
    ,       sal
    FROM       scott.emp
    ;<h3>4. Use more aggregate functions</h3>
    SELECT    deptno
    ,       MIN (job)
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;These aren't all the options, either. For example, the correct fix might be to use analytic functions instead of aggregate functions.
    How can anybody say which of these is right? All of them are the right answer for some problem.
    By the way, saying that everying in the SELECT clause must be an aggregate or in the GROUP BY clause is a bit over-simplified.
    More completely, here are the ABC's of GROUP BY:
    When you use a GROUP BY clause and/or an aggregate function, then everything in the SELECT clause must be:
    (A) an <b>A</b>ggregate function,
    (B) one of the "group <b>B</b>y" expressions,
    (C) a <b>C</b>onstant, or
    (D) something that <b>D</b>epends entirely on the above. (For example, if you "GROUP BY TRUNC(dt)", you can SELECT "TO_CHAR (TRUNC(dt), 'Mon-DD')").
    Edited by: Frank Kulash on Apr 13, 2013 1:44 PM
    Added code examples.

  • Conditional GROUP BY clause

    Hi,
    I have four columns in group by clause. I want to add conditional group by clause.
    Case 1 : If one of the  column's value is null, I don't want to include it in group by clause. Means, Now GROUP BY clause will have only 3 columns.
    Case 2 : If not null, then GROUP BY clause with all four columns.
    Please help me out on this.
    Thanks in advance.  

    Hi
    I think it won't matter, all group functions by default ignore NULLs so your result won't differ.
    select  dept, loc, sum(sal)
    from (
    select 'A' emp , 1 dept , 'P' loc , 100 sal from dual union all
    select'B',1,'P',200 from dual union all
    select'C',2,'P',300 from dual union all
    select'D',2,'P',400 from dual union all
    select'E',3, 'P',500 from dual union all
    select'F',3, 'P',600 from dual union all
    select'G',4, 'Q',700 from dual union all
    select'H', null,'Q' , 1000 from dual union all
    select'I',null ,'Q', 2000 from dual union all
    select 'J' ,null, 'Q',300 from dual)
    group by dept,loc;
    Output
    DEPT      LOC      SUM(SAL)
    1                P      300
    2                P      700
    3                P      1100
                    Q      3300
    4                Q      700
    Now by doing grouping only for NOT NULL values,
    select dept,loc, sum(sal)
    from (
    select 'A' emp , 1 dept , 'P' loc , 100 sal from dual union all
    select'B',1,'P',200 from dual union all
    select'C',2,'P',300 from dual union all
    select'D',2,'P',400 from dual union all
    select'E',3, 'P',500 from dual union all
    select'F',3, 'P',600 from dual union all
    select'G',4, 'Q',700 from dual union all
    select'H', null,'Q' , 1000 from dual union all
    select'I',null ,'Q', 2000 from dual union all
    select 'J' ,null, 'Q',300 from dual)
    where dept is not null          --------------NOT NULL Condition
    group by dept, loc;
    Output
    DEPT     LOC      SUM(SAL)
    1           P           300
    2           P           700
    3           P           1100
    4           Q           700
    Now by doing grouping only for NULL values,
    select dept,loc, sum(sal)
    from (
    select 'A' emp , 1 dept , 'P' loc , 100 sal from dual union all
    select'B',1,'P',200 from dual union all
    select'C',2,'P',300 from dual union all
    select'D',2,'P',400 from dual union all
    select'E',3, 'P',500 from dual union all
    select'F',3, 'P',600 from dual union all
    select'G',4, 'Q',700 from dual union all
    select'H', null,'Q' , 1000 from dual union all
    select'I',null ,'Q', 2000 from dual union all
    select 'J' ,null, 'Q',300 from dual)
    where dept is null               --------------NULL Condition
    group by dept, loc;
    Output
    DEPT      LOC         SUM(SAL)
                    Q           3300
    The output is same for both the conditions.

  • How to display a variable value in WAD?

    I am using a replacement path variable to filter a report by project number. While this works fine, the project number is not easily visible (only via Filter -> Display All Filter Values and this only displays the description, not the key).
    How can I display the key and the description of the project number variable at the top of the report?
    Thank you,
    Dennis

    The first part is right -
    1) drag a text element onto the page, at a location in which you want the variable value to be displayed
    2) On the left hand bottom page - go to the web item properties for the text element
    3) scroll down to the specific properties for the item - in that uncheck the first two check boxes - display general text elements & display static filter values
    4) in the next item in the properties (List of text elements) click once on the box where List is written and then clcik on the small browse button that appears.
    5) in the window that opens, in the element type field, select variable/variable value as key (as per your requirement) and then under the element ID field type in the technical name of your variable that you want to display.
    click ok and save your template and try executing it.
    See if this solves your problem.
    regards,
    Nikhil

  • Bex. Query in 3.5 : All Variable values using Text Elements not shown

    I am using a Variable, for which I am suppose to select more than 15 values . After executing the report, I am trying look for these values using Layout--> Display Text Elements --> All.
    Only first 10-11 values are shown and the rest are shown as ...
    As such, I cannot see all the values in WAD too, in the info tab. 
    Is there any limitations to display the values with text elements ?
    Any idea how to display all the values ?
    Thanks

    You are right. I can do this if I select Filter values.
    But, I am trying to show the values entered for the variables using Layout-->Display Text elements --. Alll or variables.
    These are the values shown in the web template. The filter values goes to the data analysis tab, which are fine.
    I want to display all the values in the information tab, but only few values are show and rest are shown as ...        The same is the case when I select Layout-->Display Text elements --> All or variables. after I execute the query.

  • Display all columns but only unique values in one column

    My table looks like this;
    ApprovalKey (PK)
    ApprovalCCN (Links to main table)
    ApprovalName
    ApprovalDate
    ApprovalMsg
    ApprovalResult
    Typical data would look like;
    Key CCN ApprovalName ApprovalDate ApprovalMsg ApprovalResult
    1 1 John Smith 12/12/2014 16:20:22 Testing the message False
    2 1 Andy Brown 12/12/2014 16:20:27 testing the decline False
    3 1 John Smith 12/12/2014 16:20:46 More testing True
    4 1 Andy Brown 12/12/2014 16:25:13 testing True
    5 2 Andy Brown 12/12/2014 16:25:26 testing the accept True
    6 2 John Smith 12/12/2014 16:34:04 testing, 1 2 True
    When I view data from linked table (matched via ApprovalCCN) It should display data from this table but only the latest unique entry from ApprovalName.
    eg, table from above has 4 entries for ApprovalCCN=1 but should only show the following;
    Key CCN ApprovalName ApprovalDate ApprovalMsg ApprovalResult
    3 1 John Smith 12/12/2014 16:20:46 More testing True
    4 1 Andy Brown 12/12/2014 16:25:13 testing True
    Distinct ApprovalName doesn't return all values and I can't seem to get my head around Group By to view all columns
    Any help would be appreciated

    Here is my test data;
    7 30 John Smith 12/12/2014 16:20:22 Testing the message False
    8 30 Andy Brown 12/12/2014 16:20:27 testing the decline False
    9 30 John Smith 12/12/2014 16:20:46 More testing True
    10 30 Andy Brown 12/12/2014 16:25:13 testing True
    20 30 David Jones 12/12/2014 16:25:26 testing False
    21 30 David Jones 12/12/2014 16:34:04 Testing the message True
    25 30 Me 12/12/2014 16:35:05 testing the decline False
    26 28 You 12/12/2014 16:36:05 testing the decline False
    27 28 Me 12/12/2014 16:37:05 testing True
    28 28 John Smith 12/12/2014 16:38:05 testing the decline False
    29 28 David Jones 12/12/2014 16:39:05 testing the decline False
    30 30 David Jones 14/12/2014 17:39:44 True
    31 29 David Sawyer 14/12/2014 18:51:06 declining the offer False
    32 29 David Sawyer 14/12/2014 18:51:37 My message False
    33 29 David Sawyer 14/12/2014 18:52:01 another message False
    34 29 David Sawyer 14/12/2014 18:52:16 True
    35 29 David Sawyer 14/12/2014 18:52:25 True
    36 29 David Sawyer 14/12/2014 18:52:34 True
    If ApprovalCCN=30 I get the following;
    10 30 Andy Brown 2014-12-12 16:25:13.000 testing 1 1
    30 30 David Jones 2014-12-14 17:39:44.000 1 2
    9 30 John Smith 2014-12-12 16:20:46.000 More testing 1 1
    25 30 Me 2014-12-12 16:35:05.000 testing the decline 0 1
    All I need is 3 Approved, 1 Declined
    Apologies if I wasn't clear

Maybe you are looking for

  • OVI Store and Browser On my E72 Treat my Device as...

    After reinstalling my E72-1 v 051.018, Ovi Store and Browser treat my mobile as N73. So I could not see/install some application. Missing lot of stuff Attachments: Ovi store E72 as N73.jpg ‏44 KB

  • IPhoto won't open! How can I get it to open?

    (Hey, I just checked in after not doing so for many months........ and I like this new letter template!!) I have Snow Leopard 10.6.8. (It says 10.6.5 below, but that has not yet been updated.) The message window says that I have iPhoto 9.1.5 installe

  • Where are the regular maintenance updates?

    Most expensive/professional software I own licences for receives maintenance updates and bug fix patches on a regular basis. Even with shareware and freeware, the patches and updates just keep coming. Flash Professional should certainly be no differe

  • Why doesn't my simple code work?

    I have two instances of monkMc instead of one on my workspace and the button doesn't make the object called monkMc move right. package            import flash.display.MovieClip;            import flash.events.MouseEvent;            public class Main

  • Viewing iCloud Drive in Finder

    When I open iCloud Drive in the Finder I HAVE seen folders for the apps that can save files to iCloud Drive and files within them that I have saved there. But usually all I see in iCloud Drive is a folder "iCloud Drive Upgrade - Recovered Documents".