Question on using of GROUP BY clause.

Hi, can i do a GROUP BY without having any aggregate functions? Or is there any work around for that??
I need to GROUP BY some selection but do not have any aggregate function in it.
Thanks in advance. :)

As already mentioned this can be achieved in SQL*Plus by using the break feature, but if you want it solely in SQL something like the following should do it...
SQL> ed
Wrote file afiedt.buf
  1  select decode(deptrow,1,deptno,null) as department, ename
  2  from (select deptno, row_number() over (partition by deptno order by ename) deptrow, ename
  3        from emp
  4       )
  5* order by deptno, ename
SQL> /
DEPARTMENT ENAME
        10 CLARK
           KING
           MILLER
        20 ADAMS
           FORD
           JONES
           SCOTT
           SMITH
           WILLIS
        30 ALLEN
           BLAKE
           JAMES
           MARTIN
           TURNER
           WARD
15 rows selected.
SQL>

Similar Messages

  • Problem trying to use a group by clause

    hey good day,
    i'm trying to use a group by clause in my application, but I'm getting the following error.
    Error:-  Query cannot be parsed, please check the syntax of your query. (ORA-00979: not a GROUP BY expression)
    select      "INSTRUCTOR"."EMPNUM",
          "INSTRUCTOR"."FIRSTNAME",
          "INSTRUCTOR"."LASTNAME",
          "QUALN"."SPECIALIZE_FIELD" as "SPECIALIZE_FIELD",
             "INSTRUCTOR"."USERNAME"
    from      "QUALN" "QUALN",
          "INSTRUCTOR" "INSTRUCTOR"
    where   "INSTRUCTOR"."EMPNUM"="QUALN"."EMPNUM"
    group by "INSTRUCTOR"."EMPNUM", "INSTRUCTOR"."FIRSTNAME", "INSTRUCTOR"."LASTNAME"Thanks in advance,
    Richie

    Richie wrote:
    hey thanks for your reply,
    i have tried what you have suggested, but now i got another error
    Error :- The report query needs a unique key to identify each row. The supplied key cannot be used for this query. Please edit the report attributes to define a unique key column. ORA-01446: cannot select ROWID from, or sample, a ...
    This error message is not from oracle, btu from your reporting tool. it might be MS Access or whatever other tool that you use. Some of these tools want a unique value to identify the current row. The logic applied depends on the relationship of your tables. however in your case you could do it without the group by condition. THen the rowid can still be applied to your query.
    Example
    note the usage of alias names to simplified the select
    select      i.EMPNUM ,
          i.FIRSTNAME ,
          i.LASTNAME ,
             i.USERNAME
    from      INSTRUCTOR i
    where   i.EMPNUM in (select q.EMPNUM from QUALN q);

  • How to use Group by clause in Infoset

    Hi,
    I have a infoset where I  am using two DSO .Now want to use the group by clause on basis of day, month, quarter .And also I want to use the left outer join .SO how will I do that ?
              Can somebody help me to to get these solved ?
    Regards
    Sunit

    Hi,
    for me it seems like Multiprovider is the one which we use in case when we want to go for group by option. This infoset is more kind of intersection operation.
    go through this link for more detailed info on Infoset
    http://help.sap.com/saphelp_nw2004s/helpdata/en/67/7e4b3eaf72561ee10000000a114084/content.htm
    Regards,
    rik

  • Can u write the following query without using group by clause

    select sp.sid, p.pid, p.name from product p, supp_prod sp
    where sp.pid= p.pid and
    sp.sid = ( select sid from supp_prod group by sid
    having count(*) =(select count(*) from product));
    thru this, we retrieving all the products delivered by the supplier.
    Can you write the following query without using the group by clause

      select sp.sid, p.pid, p.name
        from product p, supp_prod sp
       where sp.pid= p.pid the above query will still retrieve all the products supplied by the supplier. sub-query is not necessary.
    maybe if you can post some sample data and output will help us understand what you want to achieve.

  • Aggregate functions without group by clause

    hi friends,
    i was asked an interesting question by my friend. The question is...
    There is a DEPT table which has dept_no and dept_name. There is an EMP table which has emp_no, emp_name and dept_no.
    My requirement is to get the the dept_no, dept_name and the no. of employees in that department. This should be done without using a group by clause.
    Can anyone of you help me to get a solution for this?

    select distinct emp.deptno,dname
    ,count(*) over(partition by emp.deptno)
    from emp
    ,dept
    where emp.deptno=dept.deptno;
    10     ACCOUNTING     3
    20     RESEARCH     5
    30     SALES     6

  • Group By clause is not working

    I have two columns Department and EmpName:
    Department EmpName
    Sales empname1
    Sales empname2
    Marketing empname3
    Development empname4
    Now I want to count the number of employees in every department..
    I want the output to be
    Department Total
    Sales 2
    Marketing 1
    Development 1
    I am retrieving names of the department through a subquery
    The query I am trying to execute is:
    SELECT Department, Employee FROM
    ( SELECT ...query from other table) AS Department, count( A.EmpName) AS Employee
    FROM Employer A, EmployeeInfo B
    WHERE (A.EmpID = B.EmpID AND A.EmpCategory like 'Category2')
    GROUP BY Department
    I know that you cannot group by using aliases and hence a little work around, but still the query isn't working...I appreciate any help!!!!
    Edited by: 968775 on Oct 31, 2012 12:53 PM
    Edited by: 968775 on Oct 31, 2012 12:54 PM

    Hi,
    Welcome to the forum!
    968775 wrote:
    The query I am trying to execute is:
    SELECT Department, Employee FROM
    ( SELECT ...query from other table) AS Department, count( A.EmpName) AS Employee
    FROM Employer A, EmployeeInfo B
    WHERE (A.EmpID = B.EmpID AND A.EmpCategory like 'Category2')
    GROUP BY DepartmentRemember the ABC's of GROUP BY:
    When you use a GROUP BY clause and/or an aggregate fucntion, then every item 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')").
    In the query above, EMPOYEE is none of these. I think you meant COUNT ( employee).
    SELECT    Department
    ,         COUNT (Employee)   AS num_employees
    FROM      ...
    I know that you cannot group by usingalias name and hence a little work around, You can assign the alias in a sub-query, then use the alias in the GROUP BY clause, or anywhere else you want to, in a super-query.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    You'll get better answers faster if you always supply this information whenever you post a question.

  • Creation of view with clob column in select and group by clause.

    Hi,
    We are trying to migrate a view from sql server2005 to oracle 10g. It has clob column which is used in group by clause. How can the same be achived in oracle 10g.
    Below is the sql statament used in creating view aling with its datatypes.
    CREATE OR REPLACE FORCE VIEW "TEST" ("CONTENT_ID", "TITLE", "KEYWORDS", "CONTENT", "ISPOPUP", "CREATED", "SEARCHSTARTDATE", "SEARCHENDDATE", "HITS", "TYPE", "CREATEDBY", "UPDATED", "ISDISPLAYED", "UPDATEDBY", "AVERAGERATING", "VOTES") AS
      SELECT content_ec.content_id,
              content_ec.title,
              content_ec.keywords,
              content_ec.content content ,
              content_ec.ispopup,
              content_ec.created,
              content_ec.searchstartdate,
              content_ec.searchenddate,
            COUNT(contenttracker_ec.contenttracker_id) hits,
              contenttypes_ec.type,
              users_ec_1.username createdby,
              Backup_Latest.created updated,
              Backup_Latest.isdisplayed,
              users_ec_1.username updatedby,
              guideratings.averagerating,
              guideratings.votes
         FROM users_ec users_ec_1
                JOIN Backup_Latest
                 ON users_ec_1.USER_ID = Backup_Latest.USER_ID
                RIGHT JOIN content_ec
                JOIN contenttypes_ec
                 ON content_ec.contenttype_id = contenttypes_ec.contenttype_id
                 ON Backup_Latest.content_id = content_ec.content_id
                LEFT JOIN guideratings
                 ON content_ec.content_id = guideratings.content_id
                LEFT JOIN contenttracker_ec
                 ON content_ec.content_id = contenttracker_ec.content_id
                LEFT JOIN users_ec users_ec_2
                 ON content_ec.user_id = users_ec_2.USER_ID
         GROUP BY content_ec.content_id,
         content_ec.title,
         content_ec.keywords,
         to_char(content_ec.content) ,
         content_ec.ispopup,
         content_ec.created,
         content_ec.searchstartdate,
         content_ec.searchenddate,
         contenttypes_ec.type,
         users_ec_1.username,
         Backup_Latest.created,
         Backup_Latest.isdisplayed,
         users_ec_1.username,
         guideratings.averagerating,
         guideratings.votes;
    Column Name      Data TYpe
    CONTENT_ID     NUMBER(10,0)
    TITLE          VARCHAR2(50)
    KEYWORDS     VARCHAR2(100)
    CONTENT          CLOB
    ISPOPUP          NUMBER(1,0)
    CREATED          TIMESTAMP(6)
    SEARCHSTARTDATE     TIMESTAMP(6)
    SEARCHENDDATE     TIMESTAMP(6)
    HITS          NUMBER
    TYPE          VARCHAR2(50)
    CREATEDBY     VARCHAR2(20)
    UPDATED          TIMESTAMP(6)
    ISDISPLAYED     NUMBER(1,0)
    UPDATEDBY     VARCHAR2(20)
    AVERAGERATING     NUMBER
    VOTES          NUMBERAny help realyy appreciated.
    Thanks in advance
    Edited by: user512743 on Dec 10, 2008 10:46 PM

    Hello,
    Specifically, this should be asked in the
    ASP.Net MVC forum on forums.asp.net.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • Use of GROUP BY in SELECT

    I am considering using GROUP BY in several selects where I will access very big bsik, bsid, bsad, bsak, ecc...
    My two concerns are performance and high data volume.
    GROUP BY should reduce data arriving from DB but will it hurt performance?
    What are your considerations?
    Any ideas are welcome. I cannot seem to find anything specific for or against GROUP BY.
    thanks,
    Phillip

    Hello Philip,
    I would advise that you do not use the Group By clause in the select statements for these tables. As you have rightly said, the data volume in these tables might be a major cause for concern.
    Using the Group By clause will heavily load the database server. while in the development environment, your query  might run okay, in the productive environment it might crash. The reason : the cursor to the database would have timed out.
    The Group By operation, as you know can be simulated after you get the data into the application server. The application server processing can take some time but you can usually optimize it.
    Regards,
    Anand Mandalika.

  • -- 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.

  • Oracle 10g group by clause

    I have one SQL query using a GROUP BY clause and no ORDER BY clause is used. When executed in Oracle 8i, the query results are returned ordered by first column mentioned in the GROUP BY clause. When the same query is executed in Oracle 10g, the query results are returned withour ordering the data by the first column in the GROUP BY clause. It works only when I explicitly mention the ORDER BY clause. Can you please explain this? In Orcale 8i, is it that, by default, the data is ordered by the first column mentioned in the GROUP BY clause when ORDER BY clause is not mentioned?
    In which order does oracle 10g sorts when I use group by clause in oracle 10g

    [email protected] wrote:
    the use of group by is to group based on some column value, in this case why does the the output differs in rows. why does the output, when you use group by is not the following formatSorry, but this is a totally fruitless topic. Why are you bothering with something that is totally internal to the DBMS? If you want the data ordered, use ORDER BY, it's that simple.
    Check out this link, if you want some discussion on it:
    [http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:74320098178823]

  • Improving Performance of Group By clause

    I'm a developer who needs to create an aggreagate, or roll-up, of a large table (tens of millions of rows) using a group by clause. One of the several items I am grouping by is a numeric column called YEAR. My DBA recommended I create an index on YEAR to improve the performance of the group by clause. I read that indexes only are used when referenced in the where clause, which I do not need. Will my DBA's reccomendation help? Can you recommend a technique? Thank you.

    When you select millions of rows, grouped or not, the database has to fetch
    each of them, so an index on the group column isn't useful.
    If you have a performance problem that cannot be solved through an index on
    columns used in your where-clause, perhaps a materialzed view with the
    dimension(s) of your group clause will help.

  • Alternate to group by clause

    Hi
    I am using Oracle 8i and one of my queries is getting the data from multiple sources through a dblink from other databases (customer need cannot avoid dblinks).
    The query is using the group by clause to get the count based on specific columns and when i am not using the group by the query is pretty fast.
    select count(id), col1,col2,col3
    from source1@dblink1,
    source2@dblink1,
    source3@dblink1,
    source4@dblink1,
    source5@dblink1
    where
    group by col1,col2,col3
    Please suggest the use of other Oracle features that we can use (pl/sql table or looping in pl/sql instead of using group by ) as the amount of data is large and it has to go through several iterations and accordingly update my local db with the counts returned.
    An example will be quite helpful.
    Thanks in Advance.

    Hi,
    i have a procedure that has a cursor thats using db links as above, in the code if i open the cursor and say NULL even then it is taking about 8 mins while the cursor query is taking about 2 mins only when run separately.
    i open the cursor
    for c1 in cursor loop
    NULL;
    end loop;
    it hangs on for about 8 mins , while if i run the query of the cursor with the same parameters that i pass in the cursor at run time it takes about 2 mins.
    Dont understand where the 6 mins are going.
    If the cursor is not opened at all in the proc it gets executed in less than a second so there is no other code thats consuming time.
    Please suggest.

  • Proper use of GROUP BY

    I wrote the view below to query orders that have shipped quantity from selected warehouse subinventories. I need to compute the total of unique orders and sum for a given date along with extended price.
    I have tried many SELECTs from SCO_REQSGROSS_V including
    select TRXN_DATE
    , count(*)
    , SUM(EXT_PRC)
    from SCO_REQSGROSS_V
    where trxn_date = to_date('30-AUG-2010')
    group by TRXN_DATE, order_num
    I need a count of all the unique order numbers and there ext_prc for each date in a given date range. I keep getting back the line counts. There is something wrong with my approach using the GROUP BY clause. Do I need to use a partition clause and how would this written?
    create or replace view SCO_REQSGROSS_V (
    TRXN_DATE
    , order_num
    , EXT_PRC)
    AS
    select TRUNC(transaction_date)
    , segment1
    , ext_price
    from
    -- lines
    SELECT DISTINCT prh.segment1
    , prl.line_num
    , ool.ordered_item item_number
    , mmt.trx_source_line_id
    , mmt.transaction_reference
    , ooh.order_number
    , prl.quantity
    , ROUND(ool.shipped_quantity * prl.unit_price,2) ext_price
    , mmt.transaction_date
    , mmt.subinventory_code
    FROM apps.po_requisition_headers_all prh
    , apps.po_requisition_lines_all prl
    , apps.oe_order_headers_all ooh
    , apps.oe_order_lines_all ool
    , apps.mtl_material_transactions mmt
    WHERE prh.requisition_header_id = prl.requisition_header_id
    AND ool.header_id = ooh.header_id
    AND prh.requisition_header_id = prl.requisition_header_id
    AND ooh.source_document_id = prh.requisition_header_id
    AND ool.source_document_line_id = prl.requisition_line_id ----(+)
    AND ool.line_id = mmt.trx_source_line_id
    AND mmt.transaction_type_id = 53 -- Internal Order Pick
    AND prl.source_type_code = 'INVENTORY'
    AND prh.authorization_status = 'APPROVED'
    AND prl.item_id = ool.inventory_item_id
    AND ool.shipped_quantity IS NOT NULL
    AND ool.subinventory = mmt.subinventory_code
    AND mmt.subinventory_code IN ('APPLIANCE', 'ELECTRICAL', 'ELEVATOR', 'FURNITURE', 'HARDWARE', 'HEAT'
    , 'JANITORIAL', 'JANIT 1', 'OFFICE', 'PAINT', 'PAPER RM', 'PLUMBING', 'SKIL', 'SURPLUS', 'TOOL', 'UNIFORM')
    )

    I ran this version of your code:
    select distinct trxn_date
    count(order_num) over (partition by trunc(trxn_date)) cnt_orders,
    sum(ext_prc) over (partition by trunc(trxn_date)) total_per_txn_day -- for total_prc per day
    from SCO_REQSGROSS_V
    where trunc(trxn_date) = to_date('30-AUG-2010');
    it returned one row and total_per_txn_day was correct at 51044.21. However cnt_orders was 303. This is nominally correct but not really what I am after because what I need is a count of unique order numbers.
    The logic
    SELECT * FROM
    FROM SCO_REQSGROSS_V
    where trunc(trxn_date) = to_date('30-AUG-2010')
    order by order_num;
    returns some duplicate order numbers. I want to count the unique order numbers but still include the ext_prc for all of the orders even the duplicates.
    Here is the first several rows of output from my query above. Desired cnt_orders is 3 and the total_per_txn_day is 1528.98:
    Date..........Order#.....Ext_Prc
    30-AUG-10     399884     90
    30-AUG-10     399893     108
    30-AUG-10     403664     114.48
    30-AUG-10     403664     68.7
    30-AUG-10     403664     100.02
    30-AUG-10     403664     114.48
    30-AUG-10     403664     139.04
    30-AUG-10     403664     43.04
    30-AUG-10     403664     49.8
    30-AUG-10     403664     120
    30-AUG-10     403664     55
    30-AUG-10     403664     198.41
    30-AUG-10     403664     129.6
    30-AUG-10     403664     198.41
    Thank you.

  • GROUP BY Clause -SQL Devolper error 00904. 00000 -  "%s: invalid identifier

    I'm a real novice with SQL and I am having a problem understanding why this doesn't work. Searching the web got me to this forum, but I haven't been able to find a solution. Obviuosly I don't really understand how to use the GROUP BY clause. The SQL works fine without that clause.
    As stated in the subject I am getting this error:
    ORA-00904: "SORTPLAN": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    Error at Line: 9 Column: 17
    With this SQL statement:
    SELECT START_DTM,
    END_DTM,
    MACHINE_SORT_PROGRAM_NAME as Sortplan,
    sum(TOTAL_PIECES_FED_CNT) AS TotalFed
    FROM END_OF_RUN
    WHERE MODS_DATE BETWEEN '27-Jul-2011' AND '27-Jul-2011'
    AND MAIL_OPERATION_NBR =919
    AND SITE_ID = 81003
    GROUP BY Sortplan
    ORDER BY Sortplan;
    TIA
    Mike

    Gary,
    Thank you for pointing me in the right direction. There are so many choices here I had a hard time deciding which to use. :)
    I tried your suggestion and still got an error. I had thought I didn't need to use aggregate functions on all of the fields. I guess that was wrong, so I changed it. Once I did that the SQL worked fine.
    ORA-00979: not a GROUP BY expression
    00979. 00000 - "not a GROUP BY expression"
    *Cause:   
    *Action:
    Error at Line: 2 Column: 3
    SELECT MACHINE_SORT_PROGRAM_NAME AS Sortplan,
    min(START_DTM),
    max(END_DTM),
    sum(TOTAL_PIECES_FED_CNT) AS TotalFed
    FROM END_OF_RUN
    WHERE MODS_DATE BETWEEN '27-Jul-2011' AND '27-Jul-2011'
    AND MAIL_OPERATION_NBR =919
    AND SITE_ID = 81003
    GROUP BY MACHINE_SORT_PROGRAM_NAME
    ORDER BY Sortplan;
    Mike

  • 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

Maybe you are looking for

  • Error Installing OIM - Ebiz User Management connector

    Hi all, I am trying to install ebusiness suite user management connector 9.1.0.1.0. But, while installation, I am getting an exception Invalid Connector Installation Directory Ensure that the connector installation files are in the specified director

  • Can't empty GarageBand files from trash

    I am creating GarageBand files; when I move them to trash and then try to empty the trash, I get a message saying I need to make sure they are "unlocked" and permissons are all okay, and then it gives me two options:  Stop or Continue, neither of whi

  • Which sql can get pl/sql's version?

    Hi, how to get PL/SQL's version? such as 2.1, 2.2, 2.3 or later. v$version can not tell me the acurate version. SQL> select * from v$version; BANNER Oracle9i Release 9.2.0.6.0 - 64bit Production PL/SQL Release 9.2.0.6.0 - ProductionThanks

  • How do i recieve the rest of the song i downloaded if it is saying it did not fully download

    A song i have just downloaded did not fully download the song

  • Satellite Pro A300 - shutdown issue

    I have a brand new Satellite Pro A300-15V, which I have downgraded from Vista Business to XP Professional, using the original recovery disc. Now I have problem shutting down the computer. When I click "Turn Off" it just shuts down and then restarts a