GROUP BY and ..not a group by expression ERROR

Hi, I have the following table
===========
STUDENTS
===========
ID NAME TESTDATE MARKS
=== ====== ========= ======
1 JOHN 2007-10-01 10
1 JOHN 2007-10-02 11
1 JOHN 2007-10-02 8
2 MARY 2007-10-01 10
2 MARY 2007-10-02 7
I want to list student with maximum mark he/scored immaterial of the test - date
The following query does it:
SELECT ID, MAX(MARKS)
FROM STUDENTS
GROUP BY ID
RESULT -
ID MAX(MARKS)
=== ===========
1 11
2 10
Now, I want to show the NAME and TESTDATE in the result (remember, only for the max marks)
So I write:
SELECT ID, NAME, TESTDATE, MAX(MARKS)
FROM STUDENTS
GROUP BY ID
XXXXXXX ERROR - not a group by expression - Agreed that TESTDATE & NAME are not in group by expression. I don't want to group by TESTDATE/NAME as it won't yeild the result I am looking for.
What I am looking for is the same result from above with additional fields.
How to get around this problem? any help is highly appreciated.
THANKS IN ADVANCE.

Try this (Not tested)
SELECT ID, max(NAME) keep(dense_rank last order by marks) name,
       max(testdate) keep(dense_rank last order by marks) testdate,
       MAX(MARKS) max_mark
FROM STUDENTS
GROUP BY ID;Or using a subquery...
select id,name,testdate,marks
from
   (select id,name,testdate,marks,
      row_number() over(partition by id order by marks desc) rn
    from students)
where rn = 1;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • "not a GROUP BY expression" error when using EclipseLink

    I'm using EcliseLink 2.3.0
    The follow SQL can be executed successfully.
    select to_char(o.taskDate, 'YYYY/MM'), sum(o.plannedHrs) from TaskItem o group by to_char(o.taskDate, 'YYYY/MM');
    But the JPQL has an error when it gets excuted.
    select FUNC('to_char', o.taskDate, 'YYYY/MM'), sum(o.plannedHrs) from TaskItem o group by FUNC('to_char', o.taskDate, 'YYYY/MM')
    ERROR LOG:
    Local Exception Stack:
    Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00979: not a GROUP BY expression
    Error Code: 979
    Call: SELECT to_char(TASK_DATE, ?), SUM(PLANNED_HRS) FROM ORA47111.S_PROJ_PLAN_ITEM GROUP BY to_char(TASK_DATE, ?)
         bind => [2 parameters bound]
    Query: ReportQuery(referenceClass=TaskItemDAO sql="SELECT to_char(TASK_DATE, ?), SUM(PLANNED_HRS) FROM ORA47111.S_PROJ_PLAN_ITEM GROUP BY to_char(TASK_DATE, ?)")
         at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
         at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644)
         at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
         at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1702)
         at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:566)
         at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
         at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
         at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:264)
         at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:646)
         at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2592)
         at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2535)
         at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:846)
         at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:829)
         at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1056)
         at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:390)
         at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1144)
         at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)
         at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1501)
         at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1483)
         at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1457)
         at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:485)
         at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:742)
         at projapis.projrollup.beans.ManagedTaskItemDAOBean.calcResourcePlannedHrsInMonth(ManagedTaskItemDAOBean.java:329)
         at projapis.projrollup.beans.ManagedTaskItemDAOBean.main(ManagedTaskItemDAOBean.java:522)
    Caused by: java.sql.SQLSyntaxErrorException: ORA-00979: not a GROUP BY expression
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:440)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
         at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:837)
         at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:445)
         at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
         at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
         at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
         at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:863)
         at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1153)
         at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1275)
         at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
         at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3620)
         at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
         at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:931)
         at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:607)
         ... 22 more
    Any suggestion?
    Thanks a lot.
    Edited by: sgao on Jul 19, 2011 11:13 PM

    Hello,
    Unfortunately it is the driver complaining about the SQL that is generated, but I see no major difference from the SQL in the exception:
    SELECT to_char(TASK_DATE, ?), SUM(PLANNED_HRS) FROM ORA47111.S_PROJ_PLAN_ITEM GROUP BY to_char(TASK_DATE, ?)
    and the SQL you state works other than it looks like JPQL not SQL: select to_char(o.taskDate, 'YYYY/MM'), sum(o.plannedHrs) from TaskItem o group by to_char(o.taskDate, 'YYYY/MM');
    Does it work if the SQL in the exception is executed as a native query? Since this the driver complaining about what looks correct, I would look at the driver/database versions to see if there is a later version that might have a bug that has been fixed.
    Best Regards,
    Chris

  • Getting "ORA-00979: not a GROUP BY expression" error in Inline query

    Hello all,
    The following query when run in SCOTT user gives "ORA-00979: not a GROUP BY expression" error.
    If I remove the TRUNC function from the outer query's group by clause, then it fetches
    (My actual query is something similar to the following query. I have given emp, dept tables for convenience's sake)
    select e.empno,e.ename, AVG(e.SAL), trunc(e.hiredate),
    (select sum(sal) from emp
    where hiredate = e.hiredate) salary
    from emp e
    group by e.DEPTNO,e.EMPNO,e.ENAME, trunc(e.hiredate)
    Pls suggest how this error can be avoided.
    Regards,
    Sam

    Why not this?
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.02
    satyaki>
    satyaki>
    satyaki>select e.empno,
      2         e.ename,
      3         AVG(e.SAL),
      4         trunc(e.hiredate),
      5        (
      6           select sum(sal)
      7           from emp
      8           where hiredate = e.hiredate
      9        ) salary
    10  from emp e
    11  group by e.DEPTNO,
    12           e.EMPNO,
    13           e.ENAME,
    14           e.hiredate;
         EMPNO ENAME      AVG(E.SAL) TRUNC(E.H     SALARY
          7934 MILLER         1887.6 23-JAN-82     5583.6
          7698 Glen             1848 23-JAN-82     5583.6
          7788 SCOTT          598.95 19-APR-87     598.95
          7900 JAMES          1379.4 03-DEC-81    6650.16
          7521 WARD           226.88 22-FEB-81     226.88
          7599 BILLY            4500 10-JUN-09       4500
          2222 sp               1200 14-SEP-09       1200
          7902 FORD          5270.76 03-DEC-81    6650.16
          7566 Smith            1848 23-JAN-82     5583.6
          7654 MARTIN           1815 28-SEP-81       1815
          7839 KING             7260 17-NOV-81       7260
         EMPNO ENAME      AVG(E.SAL) TRUNC(E.H     SALARY
          7844 TURNER           2178 08-SEP-81       2178
          7876 ADAMS          159.72 23-MAY-87     159.72
    13 rows selected.
    Elapsed: 00:00:00.03
    satyaki>Regards.
    Satyaki De.

  • Its not at all startning and not giving any kind of error msg, and i restared pc many times and uninstall and installed many times, but still its not opening

    .its not at all startning and not giving any kind of error msg, and i restared pc many times and uninstall and installed many times, but still its not opening

    Also, if you downloaded earlier in the week, make sure you have the 37.0.1 updated that was released on Friday (I think).
    If needed, I suggest installing a slightly different way the next time:
    '''Clean Reinstall'''
    We use this name, but it's not about removing your settings, it's about making sure the program files are clean. As described below, this process does not disturb your existing settings. Do NOT uninstall Firefox, that's not needed.
    (1) Download a fresh installer for Firefox 37.0.1 from https://www.mozilla.org/firefox/all/ to a convenient location. (Scroll down to your preferred language.)
    (2) Exit out of Firefox (if applicable).
    (3) Rename the program folder
    ''(64-bit Windows folder names)''
    C:\Program Files (x86)\Mozilla Firefox
    to
    C:\Program Files (x86)\OldFirefox
    ''(32-bit Windows folder names)''
    C:\Program Files\Mozilla Firefox
    to
    C:\Program Files\OldFirefox
    (4) Run the installer you downloaded in #1. It should automatically connect to your existing settings.
    Any difference?
    Note: Some plugins may exist only in that OldFirefox folder. If something essential is missing, look in these folders:
    * \OldFirefox\Plugins
    * \OldFirefox\browser\plugins

  • Not a group by expression error

    1st column is status codes :StatusCode
    2nd column is thier defnition :Definition
    3rd column is no of times each code occured in those records :Notimes
    Example: 302 , moved data, 1260
    And now i want to know the % of each code occurence.
    select status_code,((notimes* 100)/sum(TOTAL_COUNT)) AS percent from Report_status,(SELECT COUNT(*) AS TOTAL_COUNT FROM Report_status)
    group by status_code.
    Could anyone help me with this query
    Getting not agroup by expression.

    SQL> create table mytable
      2  as
      3  select l id
      4       , case when l < 1261 then 302 else 303 end statuscode
      5       , case when l < 1261 then 'moved data' else 'new data' end definition
      6    from (select level l from dual connect by level <= 1500)
      7  /
    Tabel is aangemaakt.
    SQL> select statuscode
      2       , definition
      3       , count(*) notimes
      4       , 100 * ratio_to_report(count(*)) over () percentage
      5    from mytable
      6   group by statuscode
      7       , definition
      8  /
    STATUSCODE DEFINITION    NOTIMES PERCENTAGE
           302 moved data       1260         84
           303 new data          240         16
    2 rijen zijn geselecteerd.Regards,
    Rob.

  • My macbook pro os x keeps crashing lately...and not able to even send error report to apple?

    My Macbook Pro OS X keeps crashing lately.  I'm not even able to send the error report to Apple anymore.  What's wrong??

    Visel wrote:
    What's wrong??
    It keeps crashing.
    (Do you really expect other answer if you don't provide any details? And, btw, I don't think Apple accepts crash reports for 10.5 any longer.)

  • JOptionPane and not have a valid parent error(Runtime)

    I have the following code in my program ; it compiles but gives me a Runtime error :
    java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
    Here is the code :
    JOptionPane.showInternalOptionDialo(null, "Please  select a color", "Example 5",
    JOptionPane.DEFAULT_OPTION,
    JOptionPane.QUESTION_MESSAGE,
      null, new Objec{"Red" , "Green", "Blue"} , "Blue");[How do I set a parentComponent to the JOptionPane so that it works?

    Either pass something other than null as the first parameter (I'd recommend this approach), or call setRootFrame first.

  • My iTunes was working correct the other day and not I keep getting an error 7(windows error 126)

    My itunes started to get an error the other day when it when there was an update and now i can't use it . I keep getting a error 7(windows error 126)
    I've tried to remove itunes about 10 times but it still doesn't work . can someone help

    See Troubleshooting issues with iTunes for Windows updates.
    tt2

  • Not a GROUP BY expression - Oracle 10g bug?

    Hi,
    I am geting 00979. 00000 - "not a GROUP BY expression" error on Oracle 10g 10.2.0.4.0 - 64bit Production.
    To illustrate my problem I created following example.
    Let think I have some shop with clothes. Everytime I sell something, I store this information in the database - storing actual time, clothes type (trousers, socks, ...) and the size of the piece (M, L, XL, ...).
    Now, system counts statistics every hour. So it goes thrue the table with sold pieces and counts the number of pieces per clothes type and per size from the beginning of the day. It is important to realize that it is from the beginning of the day. Because of that, the number of sold pieces in the statistical table grows every hour (or is at least on the same value as in previous hour).
    Now, from this statistical table I need to make new statistic. I want a statistic how many pieces per size I sold every hour.
    I created this query for that:
    SELECT TIME, xSIZE, (SOLD  - NVL((SELECT SUM(S1.SOLD)
                                      FROM STATISTICS S1
                                      WHERE S1.xSIZE = S.xSIZE
                                        AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
                                        AND TO_CHAR(S1.TIME, 'HH24') != '23'
                                        AND S1.xSIZE IS NOT NULL
                                      GROUP BY TRUNC(S1.TIME, 'HH24'), S1.xSIZE),0)) SOLD
    FROM(
    SELECT TRUNC(S.TIME, 'HH24') TIME, S.xSIZE, SUM(S.SOLD) SOLD
    FROM STATISTICS S
    WHERE S.xSIZE IS NOT NULL
    GROUP BY TRUNC(S.TIME, 'HH24'), S.xSIZE
    --ORDER BY 1 DESC
    ) S
    ORDER BY TIME DESC, xSIZE ASCFirst I select number of sold pieces per hour per size. To get number of sold pieces for particular hour, I need to substract from this value number of sold pieces from previous hour. I decided to do this with parameter query...
    Running the query like this I get "not a GROUP BY expression" error. However if I uncomment the "ORDER BY 1 DESC" statement, the query works. I am pretty sure it has to do something with this line:
    AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
    If you modify this query like this:
    SELECT TIME, xSIZE, (SOLD  - NVL((SELECT SUM(S1.SOLD)
                                      FROM STATISTICS S1
                                      WHERE S1.xSIZE = S.xSIZE
                                        --AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
                                        AND TO_CHAR(S1.TIME, 'HH24') != '23'
                                        AND S1.xSIZE IS NOT NULL
                                      GROUP BY  S1.xSIZE),0)) SOLD
    FROM(
    SELECT TRUNC(S.TIME, 'HH24') TIME, S.xSIZE, SUM(S.SOLD) SOLD
    FROM STATISTICS S
    WHERE S.xSIZE IS NOT NULL
    GROUP BY TRUNC(S.TIME, 'HH24'), S.xSIZE
    --ORDER BY 1 DESC
    ) S
    ORDER BY TIME DESC, xSIZE ASCRemoved joining the tables on truncated time and grouping by the truncated time -> The query does not fail...
    And now the best...if you run the first query on Oracle 11g (Release 11.1.0.6.0 - 64bit Production), it works.
    Does anybody know why is the first query not working on 10g? Is there some bug or limitation for this server version?
    Please don't say me to rewrite the query in another way, I already did it, so it works on 10g as well. I am just curious why it doesn't work on 10g.
    Finally here are some data for testing.
    CREATE TABLE STATISTICS(
      TIME DATE DEFAULT SYSDATE,
      TYPE VARCHAR2(20),
      xSIZE VARCHAR2(2),
      SOLD NUMBER(5,0) DEFAULT 0
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'T-Shirt', 'M', 10);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'Socks', 'M', 3);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'T-Shirt', 'L', 1);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'Socks', 'L', 50);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'Trousers', 'XL', 7);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 2/24, 'Socks', 'XL', 3);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 1/24, 'T-Shirt', 'M', 13);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 1/24, 'Socks', 'L', 60);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 1/24, 'Trousers', 'XL', 15);
    INSERT INTO STATISTICS(TIME, TYPE, xSIZE, SOLD) VALUES(SYSDATE - 1/24, 'Socks', 'XL', 6);Edited by: user12047225 on 20.9.2011 23:12
    Edited by: user12047225 on 20.9.2011 23:45

    It is a known issue when optimizer decides to expand in-line view. You can add something (besides ORDER BY you already used) to in-line view to prevent optimizer from expanding it. For example:
    SQL> SELECT  TIME,
      2          xSIZE,
      3          (SOLD - NVL(
      4                      (
      5                       SELECT  SUM(S1.SOLD)
      6                         FROM  STATISTICS S1
      7                         WHERE S1.xSIZE = S.xSIZE
      8                           AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
      9                           AND TO_CHAR(S1.TIME, 'HH24') != '23'
    10                           AND S1.xSIZE IS NOT NULL
    11                           GROUP BY TRUNC(S1.TIME, 'HH24'),
    12                                    S1.xSIZE
    13                      ),
    14                      0
    15                     )
    16          ) SOLD
    17    FROM  (
    18           SELECT  TRUNC(S.TIME, 'HH24') TIME,
    19                   S.xSIZE,
    20                   SUM(S.SOLD) SOLD
    21             FROM  STATISTICS S
    22             WHERE S.xSIZE IS NOT NULL
    23             GROUP BY TRUNC(S.TIME, 'HH24'),
    24                      S.xSIZE
    25           --ORDER BY 1 DESC
    26          ) S
    27    ORDER BY TIME DESC,
    28             xSIZE ASC
    29  /
             SELECT  TRUNC(S.TIME, 'HH24') TIME,
    ERROR at line 18:
    ORA-00979: not a GROUP BY expression
    SQL> SELECT  TIME,
      2          xSIZE,
      3          (SOLD - NVL(
      4                      (
      5                       SELECT  SUM(S1.SOLD)
      6                         FROM  STATISTICS S1
      7                         WHERE S1.xSIZE = S.xSIZE
      8                           AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
      9                           AND TO_CHAR(S1.TIME, 'HH24') != '23'
    10                           AND S1.xSIZE IS NOT NULL
    11                           GROUP BY TRUNC(S1.TIME, 'HH24'),
    12                                    S1.xSIZE
    13                      ),
    14                      0
    15                     )
    16          ) SOLD
    17    FROM  (
    18           SELECT  TRUNC(S.TIME, 'HH24') TIME,
    19                   S.xSIZE,
    20                   SUM(S.SOLD) SOLD,
    21                   ROW_NUMBER() OVER(ORDER BY SUM(S.SOLD)) RN
    22             FROM  STATISTICS S
    23             WHERE S.xSIZE IS NOT NULL
    24             GROUP BY TRUNC(S.TIME, 'HH24'),
    25                      S.xSIZE
    26           --ORDER BY 1 DESC
    27          ) S
    28    ORDER BY TIME DESC,
    29             xSIZE ASC
    30  /
    TIME      XS       SOLD
    20-SEP-11 L           9
    20-SEP-11 M           0
    20-SEP-11 XL         11
    20-SEP-11 L          51
    20-SEP-11 M          13
    20-SEP-11 XL         10
    6 rows selected.
    SQL> Or use subquery factoring (WITH clause) + undocumented hint MATERIALIZE:
    SQL> WITH S AS (
      2             SELECT  /*+ MATERIALIZE */ TRUNC(S.TIME, 'HH24') TIME,
      3                     S.xSIZE,
      4                     SUM(S.SOLD) SOLD
      5               FROM  STATISTICS S
      6               WHERE S.xSIZE IS NOT NULL
      7               GROUP BY TRUNC(S.TIME, 'HH24'),
      8                        S.xSIZE
      9             --ORDER BY 1 DESC
    10            )
    11  SELECT  TIME,
    12          xSIZE,
    13          (SOLD - NVL(
    14                      (
    15                       SELECT  SUM(S1.SOLD)
    16                         FROM  STATISTICS S1
    17                         WHERE S1.xSIZE = S.xSIZE
    18                           AND TRUNC(S1.TIME, 'HH24') + 1/24 = S.TIME
    19                           AND TO_CHAR(S1.TIME, 'HH24') != '23'
    20                           AND S1.xSIZE IS NOT NULL
    21                           GROUP BY TRUNC(S1.TIME, 'HH24'),
    22                                    S1.xSIZE
    23                      ),
    24                      0
    25                     )
    26          ) SOLD
    27    FROM  S
    28    ORDER BY TIME DESC,
    29             xSIZE ASC
    30  /
    TIME      XS       SOLD
    20-SEP-11 L           9
    20-SEP-11 M           0
    20-SEP-11 XL         11
    20-SEP-11 L          51
    20-SEP-11 M          13
    20-SEP-11 XL         10
    6 rows selected.
    SQL> SY.

  • Group by expression not found

    Hello,
    I have a query which is giving not a group by expression error even though after having all columns in group by clause,
    The crazy here is the same query is working fine in three environments expect in one environment.
    I did a work around on this if i use the sub query my issue is getting solved but performance is going down.
    I have a union all ,collection(Multiset) clause as well. :)
    Please let me know if you people have any idea/solution on this issue?
    Is this related any environmental setup on oracle.?
    Am using oracle 10g data base and oracle 11g for my .NET.
    Thanks,
    SanS

    From my experience I have got "not a group by" expression prob.
    for a select satement like this:::
    select tab1.id,tab1.name,count(tab2.col1)
    From tab1,tab2 where tab1.id=tab2.idx
    group by tab1.id,tab1.name
    order by lower(name);
    The prob.with order by lower(name) ....without 'lower' (any other functions) working fine...and the prob occurs when the record set called from the front end(asp.net)...directly executing from the db its working fine...
    regards,
    jp@valapad

  • Should not raise no data found error

    Hi Experts,
    I am using select into statement in procedure and put some condition in select statement.
    I want if condition failed then it sould put null in to target variable . It should not raise no data found error
    e.g
    select abc into v_abc from table
    where cond1=cond;
    if this select statement no give any record it should put null into v_abc and not raise no data found error
    pls suggest something
    UG

    You could do...
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_abc varchar2(20);
      3  begin
      4    SELECT
      5      CASE
      6        WHEN (select COUNT(*) from emp where empno = 1234) > 0 THEN
      7          (select ename from emp where empno = 1234)
      8        ELSE
      9          null
    10      END
    11    INTO v_abc
    12    FROM dual;
    13* end;
    SQL> /
    PL/SQL procedure successfully completed.But that's no better than doing a check first as a seperate SQL in the PL/SQL.
    I would do this... (if I really didn't want the no_data_found exception)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_abc varchar2(20);
      3  begin
      4    SELECT max(ename)
      5    INTO v_abc
      6    FROM
      7      (
      8      SELECT ename from emp where empno = 1234
      9      UNION
    10      SELECT null from dual
    11      );
    12    dbms_output.put_line(NVL(v_abc,'!null!'));
    13* end;
    SQL> /
    !null!
    PL/SQL procedure successfully completed.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_abc varchar2(20);
      3  begin
      4    SELECT max(ename)
      5    INTO v_abc
      6    FROM
      7      (
      8      SELECT ename from emp where empno = 7782
      9      UNION
    10      SELECT null from dual
    11      );
    12    dbms_output.put_line(NVL(v_abc,'{null}'));
    13* end;
    SQL> /
    CLARK
    PL/SQL procedure successfully completed.
    SQL>

  • Ora-00979 not a group by expression

    hi , how r u ?
    my problem in group by , how include subquery in group by ,
    this query give me error ora-00979 not a group by expression ,
    please help me in this query :
    select EVV_CompScale.Code CompCode,ScaleCode ,NameEn,NameAr,RatingChar ,count(EV_CompetencyEmployee.Code) as VoteCount ,
    coalesce((select count(EV_CompetencyEmployee.code) from EV_CompetencyEmployee   join EV_EmployeeEvaluation tblEV on EV_Code=tblEV.Code  and EmployeeApprovalCMP=1 and DirectManagerApprovalCMP=1  and SeniorManagerApprovalCMP=1 and tblEV.configCode='K' where CompetencyCode=EVV_CompScale.Code  and not RatingID is null  ),1) as Total
    from EVV_CompScale left join (EV_CompetencyEmployee join EV_EmployeeEvaluation on EV_Code=EV_EmployeeEvaluation.Code and EmployeeApprovalCMP=1 and DirectManagerApprovalCMP=1 and SeniorManagerApprovalCMP=1 and EV_EmployeeEvaluation.configCode='K') on EV_CompetencyEmployee.CompetencyCode=EVV_CompScale.Code and RatingID=ScaleCode where CompConfig='K'
    and ScaleConfig='K' group by EVV_CompScale.Code,ScaleCode,RatingChar,NameEn,NameAr
    order by CompCode .
    thanks .

    Hi,
    In a GROUP BY querry, every item in the SELECT list must be one of the following
    (1) One of the GROUP BY expressions
    (2) An aggregate function
    (3) A constant
    (4) Deterministic expressions based on the above (for example, COALESCE, where all the arguments are taken from the list above)
    So if your scalar sub-query is going to be part of the GROUP BY query, it has to fit into one of those categories
    I don't see any good way of convincing the compiler that your scalar sub-query is a constant, even if it happens to rturn a constant value, but you can make it either
    (1) one of the GROUP BY expressions (compute it in a sub-query, to avoid repeating the whole scalar sub-query in the GROUP BY clause), or
    (2) an aggregate function ( e.g. MAX ((SELECT ...))).
    But the scalar sub-query doesn't have to be part of the GROUP BY query. Depending on your tables and the desired results, it might be easy to do the GROUP BY and what is now the scalar sub-query separately, and then join the two result sets.
    If you need help, it always helps to post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data
    (4) Your best attempt so far (formatted) (You posted this, but since it's unformated, it's very hard to read.)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    Formatted tabular output is okay for (3). Type these 6 characters:
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after formatted text, to preserve spacing.
    Simplify the problem if you can. For example, if your real query involves many columns and many join conditions, try to post a similar problem that has few columns and very siomple join conditions, but has the same problem as your real query.

  • ORA-00979: not a GROUP BY expression ORA-01722: invalid number error

    This is my follwing code:
    select isin,nomenclature,sum(total_balance),c_itd_rddt,c_itd_intrrt from
    select distinct instru.c_int_isin isin,
    instru.c_int_longdesc nomenclature,
    to_char(abs(acpos.acp_totbal),
    '999999999999,99,99,990.00')total_balance,
    c_itd_rddt,
    c_itd_intrrt
    from cs_instru_t instru,
    cs_instrudetls_t insdtls,
    cs_acpos_t acpos
    where instru.c_int_instruid = insdtls.c_itd_instruid
    and acpos.acp_instruid = instru.c_int_instruid
    and acpos.acp_acntnum = 'SG030001'
    and instru.c_int_instypid in (1)
    and insdtls.c_itd_rddt > ('31-Dec-2010')
    and instru.c_int_isin not in
    (select spsec.c_ssg_isinno from cs_splsecgrp_t spsec) and acpos.acp_totbal!=0
    group by instru.c_int_instruid,
    instru.c_int_longdesc,
    insdtls.c_itd_rddt,
    instru.c_int_insstts,
    instru.c_int_isin,
    insdtls.c_itd_rddt,
    acpos.acp_totbal,c_itd_intrrt
    --order by extract(year from  c_itd_rddt),c_itd_intrrt
    union
    select c_srm_prntisin isin,c_int_longdesc nomenclature,to_char(abs(acpos.acp_totbal),
    '999999999999,99,99,990.00') total_balance,c_itd_rddt,
    c_itd_intrrt from cs_instrudetls_t insdtls,cs_strmap_t map,cs_instru_strips instru,cs_acpos_t acpos
    where c_int_instruid=c_srm_prncplinsid
    and c_itd_instruid=c_int_instruid
    and c_srm_prncplinsid=acp_instruid
    and acp_acntnum='SG030001'
    )view1
    group by isin
    I want to group by isin only as only isin is same and the rest of the fields are different.But I want to display all the fields.Please Help
    I am getting the following errors:
    ORA-00979: not a GROUP BY expression
    ORA-01722: invalid number

    wat abt the other error ora-01722 not a valid number. How to take sum of total_balance which is to_char

  • Java.sql.SQLException: ORA-00979: not a GROUP BY expression in a query

    I am getting java.sql.SQLException: ORA-00979: not a GROUP BY expression
    when I run
    select count(*) from ( select count(rec_no) AS REC_NO_NUM,created_by AS
    CREATED_BY,to_char(created_dt,'Mon YYYY') AS CREATED_DT,to_date(to_char(created_dt,'Mon
    YYYY'),'Mon YYYY') AS CREATED_DATE from tbl_ndr_renal_reg where reg_no is not null and delete_ind
    = 'N' group by to_char(created_dt,'Mon YYYY'),created_by )
    But when I run the subquery below it doesn't give any error and returns rows.
    select count(rec_no) AS REC_NO_NUM,created_by AS CREATED_BY,to_char(created_dt,'Mon YYYY') AS
    CREATED_DT, to_date(to_char(created_dt,'Mon YYYY'),'Mon YYYY') AS CREATED_DATE from
    tbl_ndr_renal_reg where reg_no is not null and delete_ind = 'N' group by to_char(created_dt,'Mon
    YYYY'),created_by
    Thanks

    I tried that too still getting the same error
    SQL> select count(*) from (
    2 select count(rec_no) AS REC_NO_NUM,
    3 created_by AS CREATED_BY,
    4 to_char(created_dt,'Mon YYYY') AS CREATED_DT,
    5 to_date(to_char(created_dt,'Mon YYYY'),'Mon YYYY') AS CREATED_DATE
    6 from tbl_ndr_renal_reg
    7 where reg_no is not null
    8 and delete_ind = 'N'
    9 group by to_char(created_dt,'Mon YYYY'),created_by)
    10 ;
    to_date(to_char(created_dt,'Mon YYYY'),'Mon YYYY') AS CREATED_DATE
    ERROR at line 5:
    ORA-00979: not a GROUP BY expression

  • "ORA-00979: not a GROUP BY expression" in Oracle11g R2 (11.2.0.3).

    Hi,
    We have a query which is working in 10g and giving error "ORA-00979: not a GROUP BY expression" in Oracle11g R2 (11.2.0.3). we have found following two solution to resolve it from the internet.
    1)You can Set the hidden parameter “_FIX_CONTROL”=’5520732:OFF’ in the pfile. This parameter disables a given bug number.
    2)We can set the parameter optimizer_features_enable to a previous version of Oracle, ’11.1.0.7′
    but I am unable to find the side effects of above change, so I need to know:
    1)whcih is batter solution
    2)what are the possible side effects of both solution.

    Hi Fran,
    Please find the below query.
    SELECT DECODE(TEMP.TENOR_IND, 'L', TEMP.SHORT_NAME, NULL) PRODUCT_NAME,
    TEMP.BA_PRODTYPE_ID,
    TEMP.TENOR,
    TEMP.PERIOD_TYPE,
    TEMP.PERIOD_VALUE,
    SUM(TEMP.LIMIT_BASE_AMOUNT),
    SUM(TEMP.PNDG_LIMIT_BASE_AMOUNT),
    SUM(TEMP.GROSS_EXP_BASE_AMOUNT),
    SUM(TEMP.NETT_EXP_BASE_AMOUNT),
    SUM(TEMP.COLLATERAL_BASE_AMOUNT),
    TEMP.TENOR_IND,
    MAX(TEMP.COB_DATE),
    TEMP.CRP_PRODUCT_GROUP
    FROM (SELECT /*+INDEX(LIM BUS_CB_LIMIT_INDX01) INDEX(btpd BUS_TP_PORTFOLIO_DTLS_INDX02)*/
    MCBPT.BA_PRODTYPE_ID,
    DECODE(LIM.TENOR_IND, 'L', MCBPT.SHORT_NAME, NULL),
    LIM.LIMIT_ID,
    LIM.LIMIT_TYPE_ID,
    LIM.LIMIT_STATUS,
    LIM.OWNER_ID,
    LIM.PERIOD_TYPE,
    LIM.PERIOD_VALUE,
    LIM.LIMIT_CURR,
    LIM.LIMIT_BASE_AMOUNT,
    LIM.GROSS_EXP_BASE_AMOUNT,
    DECODE(LIM.PERIOD_TYPE,
    5,
    'Inf',
    (TO_CHAR(LIM.PERIOD_VALUE) || '-' ||
    DECODE(LIM.PERIOD_TYPE, 4, 'Y', 3, 'M', 2, 'W', 1, 'D'))) TENOR,
    LIM.TENOR_SET_ID,
    LIM.PNDG_LIMIT_CURR,
    LIM.PNDG_LIMIT_BASE_AMOUNT,
    LIM.NETT_EXP_BASE_AMOUNT,
    LIM.COLLATERAL_BASE_AMOUNT,
    LIM.COB_DATE,
    LIM.TENOR_IND,
    MCBPT.CRP_PRODUCT_GROUP,
    MCBPT.SHORT_NAME
    FROM BUS_CB_LIMIT LIM,
    BUS_TP_PORTFOLIO_DETAILS BTPD,
    MST_CB_BA_PRODUCT_TYPE MCBPT
    WHERE BTPD.ORG_ID = 108503
    AND EXISTS
    (SELECT ORG_ID
    FROM BUS_CA_CORPORATE
    WHERE ORG_STAT IN (1, 2, 4, 7, 8, 9, 22, 24, 25)
    AND BTPD.BOOKING_ENTITY = ORG_ID
    START WITH ORG_ID = 894
    CONNECT BY PRIOR ORG_ID = PARENT_ORG_ID)
    AND NOT EXISTS
    (SELECT /*+INDEX(btpd1 BUS_TP_PORTFOLIO_DTLS_INDX02)*/
    btpd1.ba_prodtype_id
    FROM bus_tp_portfolio_details btpd1
    WHERE btpd1.org_id = 108503
    AND btpd1.booking_entity = 894
    AND BTPD.BA_PRODTYPE_ID = btpd1.ba_prodtype_id
    AND EXISTS
    (SELECT ba_prodtype_id
    FROM mst_cb_ba_product_type
    WHERE product_grp_id = 1
    AND btpd1.ba_prodtype_id = ba_prodtype_id))
    AND MCBPT.BA_PRODTYPE_ID = BTPD.BA_PRODTYPE_ID
    AND BTPD.CP_STATUS = 4
    AND LIM.OWNER_ID = BTPD.PORTFOLIO_ID
    AND LIM.OWNER_TYPE = 4
    AND LIM.LIMIT_TYPE_ID = 2) TEMP
    WHERE 1 = 1
    GROUP BY TEMP.BA_PRODTYPE_ID,
    TEMP.PERIOD_TYPE,
    TEMP.PERIOD_VALUE,
    TEMP.TENOR_IND,
    TEMP.SHORT_NAME,
    TEMP.CRP_PRODUCT_GROUP
    ORDER BY TEMP.BA_PRODTYPE_ID, TEMP.PERIOD_TYPE, TEMP.PERIOD_VALUE

Maybe you are looking for

  • How do I get Front Row to work with Lion?

    Hello fellow Mac users, How do I get Front Row to work with Lion? I have an iMac 27 inch computer and is the sole entertainment provider for my bedroom. I refuse to put a TV in my room and wanted to know how to get Front Row to work again on my mac?

  • Apps no longer showing up after download

    I have quite a few apps on my Touch (165). The last three that I have downloaded through the device have loaded (I can do a search and find them), but they are not showing up anywhere on the Touch itself. I even tried hooking it up to my PC and redow

  • Need advice on importing message...

    after trying to import songs from a cd, i'm getting this message: *+an error occured...the current encoder settings fir bit rate and sample rate are not valid for this file+* any thoughts? thanks.

  • Is it possible to set tooltips from schema definition?

    Hi, I'm setting up my form to use a schema to bind fields.  What I'd like to do is to be able to define the tooltip to use for the field within the schema (so that for example when someone drags the field onto the form the tooltip is all set up too).

  • Client login solution - please recommend.

    In regards to the site http://www.myhappypeople.com I need a simple directory access solution (that hopefully doesn't let people bookmark an accessed page and go back to it without logging in again). All I want is for a client to click one link, whic