行列转换不会MySQL,呵呵,不知道是不是跟MSSQL语句一样

解决方案 »

  1.   

    对,能否把你的mssql语句贴出来学习下
      

  2.   

    给你SQL Server语句看看
    ----------------------------------------------------------------
    --建立测试表格
    create table testTable
    (id int identity(1,1),name varchar(30))insert into testTable(name)
    select 'test' union all
    select 'wsss' union all
    select 'asdfa' union all
    select 'asdf'--输出结果declare @sql varchar(1000)
    set @sql = 'select distinct ''name'' as id'
    select @sql = @sql + ',''' + name + ''' as [' + cast(id as varchar(10)) + ']' from testTable
    exec(@sql + 'from testTable')/*
    id   1    2    3     4    
    ---- ---- ---- ----- ---- 
    name test wsss asdfa asdf
    */--删除测试表格
    drop table TestTable