Skip to Main Content

SQL & PL/SQL

Announcement

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

How to sort data by a formatted date column in the select list and the GROUP BY clause?

Eslam_ElbyalyFeb 3 2020 — edited Feb 4 2020

db 12c, Apex 18.2, win 7.

Hi,

- I am trying to sort scott.emp table's data by hiredate column after I converted it to MM-YYYY format in the select list and added a group by clause.

SELECT

  TO_CHAR( hiredate, 'MM-YYYY' ) HIRE

FROM

  emp

GROUP BY

  TO_CHAR(HIREDATE,'MM-YYYY')

ORDER BY

HIREDATE;

- It shows "ORA-00979: not a group by expression" when there is not a problem with the GROUP BY clause as the error is solved when removing the ORDER BY clause not the GROUP BY clause.

Edited:

1- Why the error?

2- How to sort the data correctly?

edited the title to be more specific: Eslam_Elbyaly

This post has been answered by mathguy on Feb 3 2020
Jump to Answer
Comments
Post Details
Added on Feb 3 2020
4 comments
5,075 views