How to have Having clause in Group by

Hi All,
While using aggregated function (max,min etc) on columns, the SQL generated automatically has the non aggregated columns in the group by clause. How to specify the Having condition ?
select a , max(b)
from t
group by a
having <condition>
TIA...

Hi,
In your interface drag and drop the source column into canvas for which you want to generate the HAVING clause.
It will create filters for those columns .Now use aggregation functions like SUM, MAX,MIN, AVG etc in that filter query .
The code generated will now contain the HAVING clause in it .
Thanks,
Sutirtha

Similar Messages

  • Group by clause and having clause in select

    hi frnds
    plz give me some information of group by and having clause used in select statement with example
    thanks

    The Open SQL statement for reading data from database tables is:
    SELECT      <result>
      INTO      <target>
      FROM      <source>
      [WHERE    <condition>]
      [GROUP BY <fields>]
      [HAVING   <cond>]
      [ORDER BY <fields>].
    The SELECT statement is divided into a series of simple clauses, each of which has a different part to play in selecting, placing, and arranging the data from the database.
    You can only use the HAVING clause in conjunction with the GROUP BY clause.
    To select line groups, use:
    SELECT <lines> <s1> [AS <a1>] <s2> [AS <a2>] ...
                   <agg> <sm> [AS <am>] <agg> <sn> [AS <an>] ...
           GROUP BY <s1> <s2> ....
           HAVING <cond>.
    The conditions <cond> that you can use in the HAVING clause are the same as those in the SELECT clause, with the restrictions that you can only use columns from the SELECT clause, and not all of the columns from the database tables in the FROM clause. If you use an invalid column, a runtime error results.
    On the other hand, you can enter aggregate expressions for all columns read from the database table that do not appear in the GROUP BY clause. This means that you can use aggregate expressions, even if they do not appear in the SELECT clause. You cannot use aggregate expressions in the conditions in the WHERE clause.
    As in the WHERE clause, you can specify the conditions in the HAVING clause as the contents of an internal table with line type C and length 72.
    Example
    DATA WA TYPE SFLIGHT.
    SELECT   CONNID
    INTO     WA-CONNID
    FROM     SFLIGHT
    WHERE    CARRID = 'LH'
    GROUP BY CONNID
    HAVING   SUM( SEATSOCC ) > 300.
      WRITE: / WA-CARRID, WA-CONNID.
    ENDSELECT.
    This example selects groups of lines from database table SFLIGHT with the value ‘LH’ for CARRID and identical values of CONNID. The groups are then restricted further by the condition that the sum of the contents of the column SEATSOCC for a group must be greater than 300.
    The <b>GROUP BY</b> clause summarizes several lines from the database table into a single line of the selection.
    The GROUP BY clause allows you to summarize lines that have the same content in particular columns. Aggregate functions are applied to the other columns. You can specify the columns in the GROUP BY clause either statically or dynamically.
    Specifying Columns Statically
    To specify the columns in the GROUP BY clause statically, use:
    SELECT <lines> <s1> [AS <a 1>] <s 2> [AS <a 2>] ...
                   <agg> <sm> [AS <a m>] <agg> <s n> [AS <a n>] ...
           GROUP BY <s1> <s 2> ....
    To use the GROUP BY clause, you must specify all of the relevant columns in the SELECT clause. In the GROUP BY clause, you list the field names of the columns whose contents must be the same. You can only use the field names as they appear in the database table. Alias names from the SELECT clause are not allowed.
    All columns of the SELECT clause that are not listed in the GROUP BY clause must be included in aggregate functions. This defines how the contents of these columns is calculated when the lines are summarized.
    Specifying Columns Dynamically
    To specify the columns in the GROUP BY clause dynamically, use:
    ... GROUP BY (<itab>) ...
    where <itab> is an internal table with line type C and maximum length 72 characters containing the column names <s 1 > <s 2 > .....
    Example
    DATA: CARRID TYPE SFLIGHT-CARRID,
          MINIMUM TYPE P DECIMALS 2,
          MAXIMUM TYPE P DECIMALS 2.
    SELECT   CARRID MIN( PRICE ) MAX( PRICE )
    INTO     (CARRID, MINIMUM, MAXIMUM)
    FROM     SFLIGHT
    GROUP BY CARRID.
      WRITE: / CARRID, MINIMUM, MAXIMUM.
    ENDSELECT.
    regards
    vinod

  • How to use order by within Group by clause

    Hi All,
    I need a help as to how should i use the Order by clause so that the data should be in order with respect to one column, and at the same time whole data is grouped by some other column...like
    Select RaceNo,Venue,FP,BP from Race group by RaceNo
    Here I want to order by FP in ascending order for each group. When i am using it , whole order is changing.
    Can anybody suggest me how to use order by clause that would apply to each group of data.
    Thanks .

    order by clause should be used at the last in any query.......but in group by clause u can't use use that becoz u group according to column then no ordering is needed there......if u want to filter something then u can use having clause and later if u need to arrange then u can use order by clause.........
    i hope this eg.l gives u some clarification....
    e.g
    select deptno,count(empno)
    from dept
    group by deptno
    having count(empno) > 10
    order by deptno

  • Urgent Group by Having Clause Fails in Oracle and Works in Sybase

    Hello EveryBody I need to select curve data of curve whose date is maximum in that curve so say if i ahve
    so if records are
    curveid curvename curvedate
    1001 test1 12/12/1003
    1001 test1 12/13/1003
    1002 test2 12/12/2002
    1002 test2 12/12/2004
    I have query which run well in sybase but oracle screw up...My logic say having clause is use to filter the records of group so it should have worked in oracle.....
    Here is query
    select curveid,curvename from curve group by curveid having curvedate =max(curve_date)
    This give "not a Group by " error in oracle....It work well in sybase...
    ORA-00979: not a GROUP BY expression
    I have query which use subquery to select these records but i don't want that to use that query
    Please help

    please understand what I need the result
    for each curve i need that data of that curve who date is max in that curve group
    so say for 1001 there are two date 1/1/2001 and 1/1/2002
    I need the data of curve 1001 with date 1/1/2002
    Oracle should have some alternative solution for this....
    If i have to use subquery I do have subquery
    select a.curveid, b.curvename from curve a group by curveid having curvedate = (select max(curvedate) from curve where a.curveid=b.curveid group by curveid );
    I don't want to use that ,,,
    I want to solve my probelm using having and group/....
    Main purpose of having is to filter the records from group result so IT SHOULD DO THAT WHY ORACLE GIVE ORA ERROR FOR
    group by curve_id having curve_date=max(curve_date)
    Creators of oracle please reply

  • Use of group by and having clause

    hi frnds
    can anybody explain me the use of group by an having clause in select state ment

    Hi Rohit,
    1. GROUP BY f1 ... fn
    2. GROUP BY (itab)
    1. GROUP BY f1 ... fn
    Effect
    Groups database table data in a SELECT command on one line in the result set. A group is a set of lines which all have the same values in each column determined by the field descriptors f1 ... fn.
    ... GROUP BY f1 ... fn always requires a list in the SELECT clause. If you use field descriptors without an aggregate funciton in the SELECT clause, you must list them in the GROUP BY f1 ... fn clause.
    Example
    Output the number of passengers, the total weight and the average weight of luggage for all Lufthansa flights on 28.02.1995:
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH'       AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Note
    ... GROUP BY f1 ... fn is not supported for pooled and cluster tables.
    2. GROUP BY (itab)
    Effect
    Works like GROUP BY f1 ... fn if the internal table itab contains the list f1 ... fn as ABAP source code. The internal table itab can only have one field. This field must be of the type C and should not be more than 72 characters long. itab must be enclosed in parentheses and there should be no blanks between the parentheses and the table name.
    Note
    The same restrictions apply to this variant as to GROUP BY f1 ... fn.
    Example
    Output all Lufthansa departure points with the number of destinations:
    TABLES: SPFLI.
    DATA:   BEGIN OF WA.
              INCLUDE STRUCTURE SPFLI.
    DATA:     COUNT TYPE I.
    DATA:   END OF WA.
    DATA:   WA_TAB(72) TYPE C,
            GTAB LIKE TABLE OF WA_TAB,
            FTAB LIKE TABLE OF WA_TAB,
            COUNT TYPE I.
    CLEAR: GTAB, FTAB.
    WA_TAB = 'COTYFROM COUNT( * ) AS COUNT'. APPEND FTAB.
    APPEND WA_TAB TO FTAB.
    WA_TAB = 'CITYFROM'.
    APPEND WA_TAB TO GTAB.
    SELECT DISTINCT (FTAB)
           INTO CORRESPONDING FIELDS OF WA
           FROM SPFLI
           WHERE
             CARRID   = 'LH'
           GROUP BY (GTAB).
      WRITE: / WA-CITYFROM, WA-COUNT.
    ENDSELECT.
    Regards,
    Susmitha

  • How can user specify HAVING clause in Interactive Report

    How can user specify HAVING clause in Interactive Report after making the group by selection? Under Actions/Format, the user sees just the Group By-Sort and Group By options.

    Hi ,
    Thanks for your information.
    I am new to the APEX.*i need to show Progress bar while opening the each page* then user can know some process is happening from the backside and i don't know where i need to add and call the below function.could you please provide the steps for the progress bar.
    In my application there are almost 100 pages are there so, i need to show progress bar on each page while opening .could you please provide Global function to call on each page.
    function html_url_Progress(pThis){ 
    $x_Show('AjaxLoading');
    window.setTimeout('$s("AjaxLoading",$x("AjaxLoading").innerHTML)', 100);
    //doSubmit('APPLY_CHANGES');
    redirect(pUrl);
    Regards
    Narender B

  • Group By -- Having Clause related doubt.

    Hello,
    Can we Write/Use rather a 'Having Condition' Before a Group by Clause ..?
    If Yes then How does it Work.. I mean a 'Having' is a WHERE clause (filter) on Aggregate results ...
    SO how does Having works before grouping the Results..??

    Hi,
    Aijaz Mallick wrote:
    Hello,
    Can we Write/Use rather a 'Having Condition' Before a Group by Clause ..?What happens when you try it?
    If Yes then How does it Work.. I mean a 'Having' is a WHERE clause (filter) on Aggregate results ... Right; the HAVING clause is like another WHERE clause.
    The WHERE clause is applied before the GROUP BY is done, and the aggregate functions are computed.
    The HAVING clause is applied after the GROUP BY is done, and the aggregate functions are computed, so you can use aggregate functions in the HAVING clause.
    SO how does Having works before grouping the Results..??The order in which clauses appear in your code isn't necessarily the order in which they are performed. For example,
    SELECT    job
    ,         COUNT (*)  AS cnt
    FROM      scott.emp
    GROUP BY  job;Does it confuse you that this query can reference COUNT (*) in the SLECT clause, which is before the GROUP BY clause?
    The SELECT clause which always comes before the GROUP BY clause in code. That does not mean that the SELECT clause is completed before the GROUP BY clause is begun.
    If the documentation says that clauses must be in a certain order, then use that order, even if your current version of Oracle allows them to be in a different order. There's no guarantee that the next version of Oracle will allow something that was always said to be wrong.

  • How to have different accounting for VAT of suppliers having  two sites?

    Hello Sir/Ma'am:
    Currently we are having 3 tax rates - VAT-0, AA-12, BB-12. [(N) Tax Managers>Tax Configuration>Tax Rates]
    Vat-0 is for non-Vatable purchases.
    AA-12 is for 12% Vat on AA site purchases.
    BB-12 is for 12% Vat on BB site purchases.
    We opted to use these rates depending on the invoice and site we entered in the Payables.
    So what we did, we just choose what rate that is applicable to an invoice thru TAX CLASSIFICATION CODE column at the Invoice Lines. The LOV shows the 3 rates we made.
    But it only gives the 1 recoverable tax accounting combination from what we defaulted. As a result wrong accounting will be given to the others.
    How to have a different accounting for recoverable tax (VAT) for AA and BB?
    Thanks,
    Emgee

    I already found out a solution for my query. thanks!
    emgee

  • How do I have the list of groups as well as individuals and their information show up in address book?

    How do I have the list of groups as well as individuals and their information show up in address book?

    Let me rephrase... 
    How do I get all of the panes (groups, individuals and individual information) to show at the same time now in Lion Address Book?

  • How to have an overview on Product Group level

    Hi All,
    Customer want to have a planning in SNP to reflect their several levels of product? For example as the below structure,
    SKU numbers->Sub Brand->Brand-> Product Group
    How to have an overview on Sub Brand, Brand and product Group level?
    Best Regards,
    Bin
    Edited by: Bin Li on Mar 6, 2009 9:44 AM

    Hi Bin,
    You can define your various hierarchies of planning in SNP through Master planning object structures. (/SAPAPO/MSDP_ADMIN - Administration of Demand Planning and Supply Network Planning )
    Regards,
    R. Senthil Mareeswaran.

  • Query, Having clause

    I have a test data, like this
    with t as (
    select 1 tp, 0 sm_1, 1 sm_2, 'a' code from dual
    union all
    select 1 tp, 0 sm_1, 2 sm_2, 'b' from dual
    union all
    select 2 tp, 3 sm_1, 0 sm_2, 'c' from dual
    union all
    select 3 tp, 0 sm_1, 2 sm_2, 'a' from dual
    union all
    select 4 tp, 0 sm_1, 1 sm_2, 'a' from dual
    union all
    select 4 tp, 2 sm_1, 3 sm_2,'b' from dual
    union all
    select 4 tp, 2 sm_1, 3 sm_2, 'c' from dual
    union all
    select 5 tp, 0 sm_1, 0 sm_2, 'a' from dual
    union all
    select 5 tp, 0 sm_1, 0 sm_2, 'b' from dual
    union all
    select 5 tp, 0 sm_1, 0 sm_2, 'c' from dual)
    SQL> with t as (
    2 select 1 tp, 0 sm_1, 1 sm_2, 'a' code from dual
    3 union all
    4 select 1 tp, 0 sm_1, 2 sm_2, 'b' from dual
    5 union all
    6 select 2 tp, 3 sm_1, 0 sm_2, 'c' from dual
    7 union all
    8 select 3 tp, 0 sm_1, 2 sm_2, 'a' from dual
    9 union all
    10 select 4 tp, 0 sm_1, 1 sm_2, 'a' from dual
    11 union all
    12 select 4 tp, 2 sm_1, 3 sm_2,'b' from dual
    13 union all
    14 select 4 tp, 2 sm_1, 3 sm_2, 'c' from dual
    15 union all
    16 select 5 tp, 0 sm_1, 0 sm_2, 'a' from dual
    17 union all
    18 select 5 tp, 0 sm_1, 0 sm_2, 'b' from dual
    19 union all
    20 select 5 tp, 0 sm_1, 0 sm_2, 'c' from dual)
    21 select tp, SUM(sm_1), SUM(sm_2), code from t
    22 group by tp, code
    23 /
    TP SUM(SM_1) SUM(SM_2) CODE
    1 0 1 a
    1 0 2 b
    2 3 0 c
    3 0 2 a
    4 0 1 a
    4 2 3 b
    4 2 3 c
    5 0 0 a
    5 0 0 b
    5 0 0 c
    10 rows selected
    SQL>
    And I want to get this result
    TP SUM(SM_1) SUM(SM_2) CODE
    1 0 1 a
    1 0 2 b
    2 3 0 c
    3 0 2 a
    4 0 1 a
    4 2 3 b
    4 2 3 c
    5 0 0 a
    E.g. if SM_1 = SM_2(all of the rows) In group of tp, then return random rows with tp = 5, if
    5 0 0 c
    5 1 2 a
    5 3 1 b
    then return
    5 1 2 a
    5 3 1 b
    And I don't undersatnd how it's do with Having Clause.
    Thank you!

    SQL> with t as (
      2     select 1 tp, 0 sm_1, 1 sm_2, 'a' code from dual
      3     union all
      4     select 1 tp, 0 sm_1, 2 sm_2, 'b' from dual
      5     union all
      6     select 2 tp, 3 sm_1, 0 sm_2, 'c' from dual
      7     union all
      8     select 3 tp, 0 sm_1, 2 sm_2, 'a' from dual
      9     union all
    10     select 4 tp, 0 sm_1, 1 sm_2, 'a' from dual
    11     union all
    12     select 4 tp, 2 sm_1, 3 sm_2,'b' from dual
    13     union all
    14     select 4 tp, 2 sm_1, 3 sm_2, 'c' from dual
    15     union all
    16 select 5 tp, 0 sm_1, 0 sm_2, 'a' from dual
    17 union all
    18 select 5 tp, 0 sm_1, 0 sm_2, 'b' from dual
    19 union all
    20 select 5 tp, 0 sm_1, 0 sm_2, 'c' from dual)
    21  select tp, sm_1, sm_2, code
    22  from   (select tp,
    23                 SUM(sm_1) sm_1,
    24                 SUM(sm_2) sm_2,
    25                 code,
    26                 count(*) over (partition by tp) ct_tp,
    27                 count(*) over (partition by tp, SUM(sm_1), SUM(sm_2)) ct,
    28                 row_number() over (partition by tp order by null) rn
    29          from t
    30          group by tp, code)
    31  where   decode(ct,ct_tp,rn,1)=1
    32  and     case when sm_1 = 0 and sm_2 = 0 and ct_tp-ct > 0 then 0 else 1 end = 1;
            TP       SM_1       SM_2 C
             1          0          1 a
             1          0          2 b
             2          3          0 c
             3          0          2 a
             4          0          1 a
             4          2          3 b
             4          2          3 c
    5 0 0 a
    8 rows selected.
    SQL> with t as (
      2     select 1 tp, 0 sm_1, 1 sm_2, 'a' code from dual
      3     union all
      4     select 1 tp, 0 sm_1, 2 sm_2, 'b' from dual
      5     union all
      6     select 2 tp, 3 sm_1, 0 sm_2, 'c' from dual
      7     union all
      8     select 3 tp, 0 sm_1, 2 sm_2, 'a' from dual
      9     union all
    10     select 4 tp, 0 sm_1, 1 sm_2, 'a' from dual
    11     union all
    12     select 4 tp, 2 sm_1, 3 sm_2,'b' from dual
    13     union all
    14     select 4 tp, 2 sm_1, 3 sm_2, 'c' from dual
    15     union all
    16 select 5 tp, 0 sm_1, 0 sm_2, 'a' from dual
    17 union all
    18 select 5 tp, 1 sm_1, 0 sm_2, 'b' from dual
    19 union all
    20 select 5 tp, 2 sm_1, 0 sm_2, 'c' from dual)
    21  select tp, sm_1, sm_2, code
    22  from   (select tp,
    23                 SUM(sm_1) sm_1,
    24                 SUM(sm_2) sm_2,
    25                 code,
    26                 count(*) over (partition by tp) ct_tp,
    27                 count(*) over (partition by tp, SUM(sm_1), SUM(sm_2)) ct,
    28                 row_number() over (partition by tp order by null) rn
    29          from t
    30          group by tp, code)
    31  where   decode(ct,ct_tp,rn,1)=1
    32  and     case when sm_1 = 0 and sm_2 = 0 and ct_tp-ct > 0 then 0 else 1 end = 1;
            TP       SM_1       SM_2 C
             1          0          1 a
             1          0          2 b
             2          3          0 c
             3          0          2 a
             4          0          1 a
             4          2          3 b
             4          2          3 c
    5 1 0 b
    5 2 0 c
    9 rows selected.Nicolas.

  • Use of Where and having clause

    Hi all,
    I always have a doubt about use of HAVING and WHERE clause,
    suppose I have table T1 with only one column C1
    CREATE TABLE T1
    (C1 VARCHAR2(1) );
    which having data by following INSERT scripts
    INSERT INTO T1 VALUES('A');
    INSERT INTO T1 VALUES('B');
    INSERT INTO T1 VALUES('C');
    INSERT INTO T1 VALUES('A');
    INSERT INTO T1 VALUES('B');
    INSERT INTO T1 VALUES('A');
    Now I want result as follows
    C1 ==== COUNT(C1)
    ==============
    B ===== 2
    A ===== 3
    So out of query 1 and 2 which approach is right ?
    1) SELECT C1,COUNT(C1) FROM T1
    WHERE C1<>'C'
    GROUP BY C1
    ORDER BY C1 DESC;
    2) SELECT C1,COUNT(C1) FROM T1
    GROUP BY C1
    HAVING C1<>'C'
    ORDER BY C1 DESC;
    Edited by: user13306874 on Jun 21, 2010 2:36 AM

    In SQL, it's always best to filter data at the earliest moment possible.
    In your example the WHERE clause would be that moment:
    SQL> explain plan for
      2  select c1,count(c1)
      3  from t1
      4  where c1 != 'C'
      5  group by c1
      6* order by c1 desc;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3946799371
    | Id  | Operation          | Name | Rows  | Bytes |
    |   0 | SELECT STATEMENT   |      |     5 |    10 |
    |   1 |  SORT GROUP BY     |      |     5 |    10 |
    |*  2 |   TABLE ACCESS FULL| T1   |     5 |    10 |
    Predicate Information (identified by operation id):
       2 - filter("C1"!='C')
    18 rows selected.
    SQL>As you can see the filter is applied during the scan of T1.
    Whereas in the HAVING case:
    SQL> explain plan for
      2  select c1,count(c1)
      3  from t1
      4  group by c1
      5  having c1 != 'C'
      6* order by c1 desc;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3146800528
    | Id  | Operation           | Name | Rows  | Bytes |
    |   0 | SELECT STATEMENT    |      |     6 |    12 |
    |*  1 |  FILTER             |      |       |       |
    |   2 |   SORT GROUP BY     |      |     6 |    12 |
    |   3 |    TABLE ACCESS FULL| T1   |     6 |    12 |
    Predicate Information (identified by operation id):
       1 - filter("C1"!='C')
    18 rows selected.
    SQL>The scan is done after all groups have been computed: one of which was computed in vain, since it will be filtered away due to the HAVING clause.
    In general I would use as a guideline: if you are not using aggregate functions in your HAVING clause predicate, then move that predicate to the WHERE portion of your query.
    Edited by: Toon Koppelaars on Jun 21, 2010 11:54 AM

  • Having clause with Analytic function

    can you pls let me know if we can use HAVING clause with analytic function
    select eid,empno,sum(sal) over(partition by year)
    from employee
    where dept = 'SALES'
    having sum(sal) > 10000I m getting error while using the above,
    IS that we can use HAVING clause with partition by
    Thanks in advance

    Your having clause isn't using an analytical function, is using a regular aggregate function.
    You also can't use analytical functions in the where clause or having clause like that as they are windowing functions and belong at the top of the query.
    You would have to wrap the query to achieve what you want e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, total_sal
      2  from (
      3        select deptno,sum(sal) over (partition by deptno) as total_sal
      4        from   emp
      5       )
      6  group by deptno, total_sal
      7* having total_sal > 10000
    SQL> /
        DEPTNO  TOTAL_SAL
            20      10875
    SQL>

  • HAVING clause, or ORDER BY clause ....ERROR

    hi i have following query which throws error plz find the solution for the query to go safe..
    Select C.src_cd,
    D.src_nm,
    count(*) supp_clm_count,
    (CASE WHEN A.clm_ttladjamt > 0 then A.clm_ttladjamt else A.clm_ttlreqamt END) as amount
    From IWOWNER.WC_clm A,
    IWOWNER.WC_clm_srvc B,
    SHOWNER.WC_SRC C,
    SHOWNER.WC_SRC_lang D
    where A.clm_id = B.clm_id
    and A.rcv_loc_id = C.src_id
    and C.src_id = D.src_id
    and TRANSLATE(A.clm_rqst_type_cd) = 'SUPPLIERCLAIM'
    and TRANSLATE(A.clm_typ_cd) in ('WARRANTY','PRE-DELIVERY')
    and DATE(A.clm_create_dt) between '01/01/2000' and '01/01/2010'
    Group by C.src_cd, D.src_nm
    ERROR:
    SQLSTATE: 42803, SQLERRMC: CLM_TTLADJAMT
    Message: An expression starting with "CLM_TTLADJAMT" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified

    Hi,
    With analytic function
    /* Formatted on 2009/07/22 10:47 (Formatter Plus v4.8.8) */
    SELECT DISTINCT c.src_cd, d.src_nm,
                    COUNT (1) OVER (PARTITION BY c.src_cd, d.src_nm)
                                                                   supp_clm_count,
                    SUM (CASE
                            WHEN a.clm_ttladjamt > 0
                               THEN a.clm_ttladjamt
                            ELSE a.clm_ttlreqamt
                         END
                        ) OVER (PARTITION BY c.src_cd, d.src_nm) AS amount
               FROM iwowner.wc_clm a,
                    iwowner.wc_clm_srvc b,
                    showner.wc_src c,
                    showner.wc_src_lang d
              WHERE a.clm_id = b.clm_id
                AND a.rcv_loc_id = c.src_id
                AND c.src_id = d.src_id
                AND a.clm_rqst_type_cd = 'SUPPLIERCLAIM'
                AND a.clm_typ_cd IN ('WARRANTY', 'PRE-DELIVERY')
                AND a.clm_create_dt BETWEEN TO_DATE ('01/01/2000', 'dd/mm/yyyy')
                                        AND TO_DATE ('01/01/2010', 'dd/mm/yyyy')

  • Subquery in the HAVING Clause

    Hello all,
    i'm getting error when i try to write sub query in having clause. check out my query
    select  ROUND( Count( distinct  Sales2011_DIVDPTA.DIVDPTA_Item_Dept ),0)  AS  "F1" , ROUND( Count( Sales2011.Sales2011_DG1.Item_Season ),0)  AS  "F2"  
    from Sales2011.Sales2011_JT    
      INNER JOIN Sales2011.Sales2011_DG1 On Sales2011.Sales2011_DG1.DG1_ID =Sales2011.Sales2011_JT.DG1_ID   
    LEFT JOIN Sales2011.Sales2011_DIVDPTA On nvl(Sales2011.Sales2011_DIVDPTA.DIVDPTA_ITEM_DIVISION,' ')=nvl(Sales2011.Sales2011_DG1.Item_Division,' ')
      AND  nvl(Sales2011.Sales2011_DIVDPTA.DIVDPTA_ITEM_DEPT,' ')=nvl(Sales2011.Sales2011_DG1.Item_Dept,' ')       
    having ( ROUND( Count( Sales2011.Sales2011_DG1.Item_Season ),0)     in ( 0)
    But it is not executed if I use the sub query in having clause
    select  ROUND( Count( distinct  Sales2011_DIVDPTA.DIVDPTA_Item_Dept ),0)  AS  "F1" ,  ROUND( Count( Sales2011.Sales2011_DG1.Item_Season ),0)  AS  "F2"   
    from Sales2011.Sales2011_JT       
    INNER JOIN Sales2011.Sales2011_DG1 On Sales2011.Sales2011_DG1.DG1_ID =Sales2011.Sales2011_JT.DG1_ID   
    LEFT JOIN Sales2011.Sales2011_DIVDPTA On nvl(Sales2011.Sales2011_DIVDPTA.DIVDPTA_ITEM_DIVISION,' ')=nvl(Sales2011.Sales2011_DG1.Item_Division,' ')
    AND  nvl(Sales2011.Sales2011_DIVDPTA.DIVDPTA_ITEM_DEPT,' ')=nvl(Sales2011.Sales2011_DG1.Item_Dept,' ')        
    having ( ROUND( Count( Sales2011.Sales2011_DG1.Item_Season ),0)
    in ( select   ROUND( Count(
    Sales2011.Sales2011_DG1.Item_Season ),0)  from    Sales2011.Sales2011_DG1 )
    Error at Command Line:1 Column:0
    Error report:
    SQL Error: ORA-00979: not a GROUP BY expression
    00979. 00000 -  "not a GROUP BY expression"
    *Cause:   
    *Action:any help ???

    Sorry unintentionally i have posted my question here.
    will you please elaborate this? Becoz i'm not using group by clause in both query. First query run successfully but as i put sub query in having clause it raised an error. will you tell where i'm committing mistake?
    Aggregates in the HAVING clause do not need to appear in the SELECT list. If the HAVING clause contains a subquery, the subquery can refer to the outer query block if and only if it refers to a grouping column.Edited by: Oracle Studnet on Aug 14, 2011 11:28 PM

Maybe you are looking for

  • Std report to dispaly Sales Order and Profit center data

    Hi, I want to display list of Sales Order and profit center in one report  for that Sales organisation Is there any T-code where i can view Sales Order and its Profit center. **Plz if anyone knows abt this reply soon. Thanks AKASH Edited by: AKASH TA

  • Vendor due date analysis

    Frnds I need to generate the report which consists of Vendor number, vendor name and invoice no with total amount of invoice and due date of that invoices. is it possible i cna get all the above required information in one report? actuall i tried to

  • How can I retrieve deleted Mail inbox mail messages and sent messages?

    I moved location and found (once again) that I could not send messages. In the past I have moved between Apple support and BT support to fix the problem. This time the BT IT technical support guy took over the screen, created a new account, made sure

  • Using variables as table names. Ideas for alternative designs

    Hi, I am designing an application which uses synonyms to pull information from 'client' DBs via DB Links. The synonyms are created with a DB_ID in the name (example: CUSTOMER_100, CUSTOMER_200... where 100 and 200 are DB IDs from 2 separate client DB

  • Standard variant of SAP query is loaded automatically

    Hi! I have created SAP query and standard variant via SQ01. When I run my query (via transaction) values of variant are loaded automatically in a selection screen and in my case I need empty selection screen at the beginning and values should appear