简体   繁体   中英

How to order the records from different records with matching data in two differents columns as continous rows in output

Need help with Oracle query which will provide the output in below the format.

Sample table

c1 c2 c3 c4
-- -- -- -- 
 A  1 A1
 B  2 B1 C1
 D  6 E2 A1
 A  2    A1
 C  3 C1
 D  4 D1 E1

I want to join same table where data in 3rd Column matches the data in 4th and expecting the data to be sorted as subsequent records as below

c1 c2 c3 c4
-- -- -- -- 
 A  1 A1
 A  2    A1
 D  6 E2 A1
 B  2 B1 C1
 C  3 C1

That's not a grouping, it's a sorting that you need:

select *
from your_table
order by coalesce(col1,'ZZZ') desc, 
                  col2 desc --coalesce will use 'ZZZ' to order if column is null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM