没有排序字段的情况下怎么reverse一张表

请问在没有排序字段的情况下怎么reverse一张表?例如假设有下面一张表:

col0	col1
7.2478	6.7432
6.1262	2.4681
1.065	9.5865

倒置后变成:
col0	col1
1.065	9.5865
6.1262	2.4681
7.2478	6.7432




请先 登录 后评论

1 个回答

wale

两种方法:

1.用rowNo生成行号,然后用order by+ desc 排序,例如:

select * from t order by rowNo(col0) desc

2.把表当作一个list来处理,例如:

t[t.rows():0]


用下面方法在我本地电脑上测试,即对一个有1百万行记录的内存表,运行1000次:

t=table(1..1000000 as id,1..1000000 as v)
timer(1000) t1=t[t.rows():0]
timer(1000) t1=select * from t order by rowNo(id) desc

分别耗时951ms和19645ms,即方法2的性能是方法1的20倍。





请先 登录 后评论