'Sort data-Oracle on two columns with some condition
I want to sort the data by date and then by sequence number. I have done this sorting but when I check the result I get some unordered data for the sequence number and want to fix that. Let's understand by example-
If you see the attachment-
I get seq_num "24231" after "24229" which is true by date order. But I need seq_num also in order after date sort if those are not.
Requirement-
- Seq_num is rolling basis- that is 24220-24235 for every day. It preserves the sequence. So if my sequence ended "24224" on last day the next day's sequence is "24225". So I can't do the sort by seq_num at first. Sorting by date is first priority.
- If you check the image I have seq_num in a different order for the "24229-24231-24230-24232" I need to get this as "24229-24230-24231-24232".
My sample code-
SELECT /*+parallel 32*/SOURCEID,
Sourcename,
Inputfilename,
Substr(Inputfilename,Instr(Inputfilename,'_',-1)+1,5) Seq_Num,
Substr(Inputfilename,1,16) Element_Id,
To_Date(Substr(Inputfilename,Instr(Inputfilename,'_',+1,6)+1,14),'YYYYMMDD HH24:MI:SS') Dt
From Mm_Sequence_Check_Test
Order By 6,4;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|