假设下表:
Select *
from TestTable;
Name value
B 3
C 1
A 2
我想输出如下:
Name value
A 1
B 2
C 3
请注意,结果Name
与value
列中对应的序数值匹配。
有人帮忙,我怎么写SQL语句?
答案 0 :(得分:3)
select
Name, Value
from
-- Order the Name table
(select row_number() over (order by name) as id, Name from TestTable) as n
inner join
-- Order the Value table
(select row_number() over (order by value) as id, Value from TestTable) as v
on n.id = v.id -- Combine two table by the ordered id
答案 1 :(得分:0)
public class ImageAdapter extends PagerAdapter{
private Context context;
private String passedString;
public ImageAdapter(Context context, String passedString) {
this.context = context;
this.passedString = passedString;
}
@Override
public int getCount() {
return 0;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return false;
}
}
答案 2 :(得分:0)
WITH
test1 AS
(SELECT ROW_NUMBER() over(order by Name)as id , Name FROM Testing ),
test2 AS
(SELECT ROW_NUMBER() over(order by value)as id , value FROM Testing )
SELECT Name,Value
FROM test1
JOIN test2
ON test1.id=test2.id