Home > Net >  How to flip records of an in-memory table upside down?
How to flip records of an in-memory table upside down?

Time:10-18

I have an in-memory table as follows:

A1 B1 C1 
A2 B2 C2
A3 B3 C3

How can I turn it into the table below?

A3 B3 C3 
A2 B2 C2
A1 B1 C1

I have tried by adding an auto-increment field. Use keyword order by and desc to sort the records based on the new column on descending order. Then, I get the expected result after deleting this column. I wonder if there is a more convenient way to get a reversed table.

CodePudding user response:

You can use the rowNo function to sort columns without adding a new auto-increment field.

t=table(`A1`A2`A3 as col1,`B1`B2`B3 as col2,`C1`C2`C3 as col3)
select * from t order by rowNo(col1) desc

Output:

col1 col2 col3
---- ---- ----
A3   B3   C3  
A2   B2   C2  
A1   B1   C1 
  • Related