Query (merged 3) [message #365281] |
Thu, 11 December 2008 05:18 |
Akash Nathile
Messages: 38 Registered: October 2006 Location: Pune
|
Member |
|
|
Hi All,
I have a table ABC with following sturcture.
Desc abc
id number
section varchar2(10)
select * from abc;
ID SECTION
------------------------
1 REC
2 CP
3 TC
4 TC
5 CP
6 REC
7 CP
8 CP
I want to sort them in such a manner that every section come only after repetition of other available sections, e.g.
ID SECTION
------------------------
2 CP
1 REC
3 TC
5 CP
6 REC
4 TC
7 CP
8 CP
Thanks in advance.
|
|
|
|
|
|
Re: Query [message #365293 is a reply to message #365285] |
Thu, 11 December 2008 05:43 |
Akash Nathile
Messages: 38 Registered: October 2006 Location: Pune
|
Member |
|
|
Sorry Michel,
I will keep in mind.
This is test data.
create table abc
(id number,
SECTION varchar2(10)
);
insert into abc
values (1,'REC');
insert into abc
values (2,'CP');
insert into abc
values (3,'TC');
insert into abc
values (4,'TC');
insert into abc
values (5,'CP');
insert into abc
values (6,'REC');
insert into abc
values (7,'CP');
insert into abc
values (8,'CP');
commit;
Select * from ABC;
ID SECTION
------------------------
1 REC
2 CP
3 TC
4 TC
5 CP
6 REC
7 CP
8 CP
Now I want to sort them in such a manner that every section come
only after repetition of other available sections, e.g.
ID SECTION
------------------------
2 CP
1 REC
3 TC
5 CP
6 REC
4 TC
7 CP
8 CP
Regards,
Akash
|
|
|
Re: Query [message #365295 is a reply to message #365293] |
Thu, 11 December 2008 05:49 |
S.Rajaram
Messages: 1027 Registered: October 2006 Location: United Kingdom
|
Senior Member |
|
|
O.k I assume you want to order by id and also the preference should be given to CP, REC and TC.
Clue is already been given to in one of your duplicate post. I repeat the same clue again. User analytic function for example row_number() with partition clause and order by <column> on which you want to do the ordering. Use this order your final result along with the customised ordering on the text.
Regards
Raj
|
|
|
|
Re: Query [message #365301 is a reply to message #365295] |
Thu, 11 December 2008 05:57 |
|
Michel Cadot
Messages: 68718 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Now I merged the topics.
STOP multiposting and follow Forum Guide.
Regards
Michel
|
|
|