sql - How to select the same column twice with different order -
here problem. need order same colum in diferent ways in same select. first asc , desc.
example:
table1
+--------+-----+ | name | age | +--------+-----+ | coa | 20 | | bami | 12 | | alice | 50 | +--------+-----+
the results should be:
+------+-----+ | age | age | +------+-----+ | 12 | 50 | | 20 | 20 | | 50 | 12 | +------+-----+
i want same column first orders ascendant , descendant.
i trying
query
select t1.age, t2.age table1 t1 inner join table1 t2 on t1.name=t2.name order t1.age asc, t2.age desc
but in result, both columns ordered in same way.
anyone knows how solve problem?
that weird requirement. can using row_number()
, join:
select t1a.age, t1b.age (select t1.*, row_number() on (order age asc) seqnum table1 t1 ) t1a join (select t1.*, row_number() on (order age desc) seqnum t1 ) t1b on t1a.seqnum = t1b.seqnum order t1a.age;
Comments
Post a Comment