有些人需要SQL语句的帮助

时间:2015-08-04 06:26:34

标签: sql sql-server

假设下表:

Select * 
from TestTable;

  Name      value
   B          3
   C          1
   A          2

我想输出如下:

  Name      value
   A          1
   B          2
   C          3

请注意,结果Namevalue列中对应的序数值匹配。 有人帮忙,我怎么写SQL语句?

3 个答案:

答案 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