表a  中姓名字段中的姓名是乱放的。如姓名
  
张三
李四
王五
张思
...我想把此表按照姓名排序,并把排序后的结果放在一新表b中。请问如何写sql语句

解决方案 »

  1.   

    select * 
      into newtalbe
    from ta
    order by name
      

  2.   

    -- Test Data: ta
    IF OBJECT_ID('[ta]') IS NOT NULL 
        DROP TABLE [ta]
    Go
    CREATE TABLE ta([姓名] NVARCHAR(2))
    Go
    INSERT INTO ta
        SELECT '张三' UNION ALL
        SELECT '李四' UNION ALL
        SELECT '王五' UNION ALL
        SELECT '张思' 
    GO
    --Start
    SELECT 
    * into newtable
    FROM
    TA
    order by [姓名]select * from newtable
    ;
    drop table newtable--Result:
    /*姓名
    ----
    李四
    王五
    张三
    张思(4 行受影响)
    */
    --End 
      

  3.   

    select * 
    into newtalbe
    from ta
    order by name
    这个的结果和
     select * from newtalbe 他的结果不一样。
    newtalbe 中的内容还是没排序。
      

  4.   


    order by [姓名],[性别]
    就不行了
      

  5.   

    15L其实是对的聚集索引
    create clustered index IX_表a_姓名 on 表a (姓名 asc)没聚集索引姓名不可能有序的,插入1条新纪录就乱了。