怎么利用存储过程把图一中的数据变为图二中的形式
图一:+------+------+------+
| col1 | col2 | col3 |
+------+------+------+
|    1 |    2 |    3 |
|    4 |    5 |    6 |
|    7 |    8 |    9 |
+------+------+------+图二:
+------+------+------+
| col1 | col2 | col3 |
+------+------+------+
|    9 |    8 |    7 |
|    6 |    5 |    4 |
|    3 |    2 |    1 |
+------+------+------+

解决方案 »

  1.   

    select col3 col1,
           col2 col2,
           col1 col3
    from tb
    order by col desc
      

  2.   

    DECLARE @a TABLE(a INT,b INT,c INT)
    insert @a select 1 , 2 , 3 
    UNION ALL SELECT 4 , 5 , 6
    UNION ALL SELECT 7 , 8 , 9
    SELECT a=c,b,c=a FROM @a  ORDER BY a DESC--result
    /*a           b           c           
    ----------- ----------- ----------- 
    9           8           7
    6           5           4
    3           2           1(所影响的行数为 3 行)*/
      

  3.   


    --列互换下就行了。
    --> 测试数据: [tb]
    if object_id('[tb]') is not null drop table [tb]
    create table [tb] (col1 int,col2 int,col3 int)
    insert into [tb]
    select 1,2,3 union all
    select 4,5,6 union all
    select 7,8,9select col3 col1,col2 col2,col1 col3 from tb
    order by col1 desc