0

I have a table :

ID     COUNTER     Date
----   -------  -----------
 1        05    23-07-2019
 2        01    23-06-2017
 3        10    02-06-2019
 4        14    01-12-2016
 5        03    23-11-2018
 6        07    23-11-2015

Now I want to Sort first Date column , based on that sort result sort counter .How to write a query for this. If I have a more than one date for a particular year than , sort according to counter for that particular year records. Like this :

  COUNTER      Date
  -------   ----------- 
     10       02-06-2019   
     05       23-07-2019     

     03       23-11-2018
     01       23-06-2017
     14       01-12-2016
     07       23-11-2015

Any help would be appreciated!. Thanks.

0

1 Answer 1

4

order by to_char(date_column, 'YYYY') desc, counter desc

order by trunc(date_column, 'YYYY') desc, counter desc

drop table t1 purge;
create table t1 (counter varchar2(2), date_column date);
insert into t1 values ('05', date'2019-07-23');
insert into t1 values ('01', date'2017-06-23');
insert into t1 values ('10', date'2019-06-02');
insert into t1 values ('14', date'2016-12-01');
insert into t1 values ('03', date'2018-11-23');
insert into t1 values ('07', date'2015-11-23');
commit;

select * from t1 order by trunc(date_column, 'YYYY') desc, counter desc;

CO DATE_COLUM
-- ----------
10 02-06-2019
05 23-07-2019
03 23-11-2018
01 23-06-2017
14 01-12-2016
07 23-11-2015
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.