oracle - Get all rows from a table having a particular column value but ordered by different column value -
i having trouble formulating question, give example demonstrate. consider table as,
create table abc ( pid number(10,0) not null, disp_col varchar2(100 byte), val_col varchar2(20 byte), ord_col1 number(5,2), ord_col2 number(5,2), constraint pk_pid primary key ( pid ) );
and data have is,
pid | disp_col | val_col | ord_col1 | ord_col2 ---------------------------------------------- 1 | disp1 | val1 | 1 | 14 2 | disp2 | val26 | 2 | 22 3 | disp1 | val8 | 1 | 17 4 | disp1 | val56 | 1 | 9 5 | disp2 | val9 | 2 | -10 6 | disp3 | val12 | 2 | 20 7 | aisp1 | val7 | 2 | -3
now based on descending ordering of ord_col1, ord_col2, want unique disp_col values , rows of disp_col value follow. data should like,
pid | disp_col | val_col | ord_col1 | ord_col2 ---------------------------------------------- 2 | disp2 | val26 | 2 | 22 5 | disp2 | val9 | 2 | -10 6 | disp3 | val12 | 2 | 20 7 | aisp1 | val7 | 2 | -3 3 | disp1 | val8 | 1 | 17 1 | disp1 | val1 | 1 | 14 4 | disp1 | val56 | 1 | 9
a simple order ord_col1 desc, ord_col2 desc me order want disp_col occur want same valued rows follow that.
i kind of new oracle , pl/sql, appreciated. in advance.
select * abc order ord_col1 desc, disp_col asc, ord_col2 desc;
http://sqlfiddle.com/#!4/40401/18
you need order disp_col
in asc
in order result want. see updated fiddle , code above. give want question.
Comments
Post a Comment