解决方案 »

  1.   

    写了个最烂的select tt1.codee, scoreA,scoreB,scoreC from 
    (select t1.codee,scoreA,scoreB from (
    (select codee, concat(s1,',',s2,',',s3,',',s4) as scoreA from t
    where coder='A') t1
    join
    (select codee, concat(s1,',',s2,',',s3,',',s4) as scoreB from t
    where coder='B') t2
    on t1.codee=t2.codee
    ) ) tt1
    join
    (select codee, concat(s1,',',s2,',',s3,',',s4) as scoreC from t
    where coder='C') t3 
    on tt1.codee = t3.codee
      

  2.   

    再来select codee,
    MAX(case coder when 'A' then concat(s1,',',s2,',',s3,',',s4) else null end) AS scoreA,
    MAX(case coder when 'B' then concat(s1,',',s2,',',s3,',',s4) else null end) AS scoreB,
    MAX(case coder when 'C' then concat(s1,',',s2,',',s3,',',s4) else null end) AS scoreC
    from t 
    GROUP BY codee
      

  3.   


    谢谢!
    如果是100个人呢?
    主要是最后得出,
    所有的评分记录。
    横向是评分人,然后下面是4个评分值
    纵方向是被评分的比如这里的员工表为 tab_staff
             评分表为 tab_pingfenDetail本想用游标写的,一次性获取最终的结果,然后用存储过程包装起来。
    最后表示层使用时,直接调用这个存储过程。 不知道如何写才好。
      

  4.   

    http://bbs.csdn.net/topics/240002706动态行转列,上班去,回到公司没人回复我再看
      

  5.   


    SELECT 'A' 评分人,'A' 被评分人,6 item1, 8 item2,9 item3,7 item4
    into #t
    UNION ALL SELECT 'A','B',8, 9, 4, 5
    UNION ALL SELECT 'A','C',6, 7, 8, 5
    UNION ALL SELECT 'B','A',5, 6,  7,  8
    UNION ALL SELECT 'B','B',6, 9, 8, 5
    UNION ALL SELECT 'B','C',6, 7, 9, 5
    UNION ALL SELECT 'C','A',5, 6,  7,  8
    UNION ALL SELECT 'C','B',6, 9, 8, 5
    UNION ALL SELECT 'C','C',6, 7, 9, 5declare @str nvarchar(max)='';select @str =@str+N',MAX(case 评分人 when '''+评分人+N''' then concat(item1,'','',item2,'','',item3,'','',item4) else null end) AS score'+[评分人]
    from (select distinct [评分人] from  #t) t;select @str= N'select 被评分人'+ @str
    +N' from #t 
    GROUP BY 被评分人'Exec (@str)
      

  6.   


     十分感谢!
    我的是用sql server,没有concat函数
    最终显示的是一个表格数据,没有逗号的.感觉第一行,估计在Sql语句中不好体现吧。 比如评分人A(是跨越4个列的,这个或许要在代码显示成体现)
    ===== ---- 评分人A ------------ |---- 评分人B -----------|---- 评分人B ------------
    被评分人|item1|item2|item3|item4 |item1,item2,item3,item4 |item1,item2,item3,item4 |
    A| 6| 8, 9, 7                   |5,6,7,8                             |7      8           9       5
    B| 8, 9, 4, 5                   |5,6,7,8                             |7,8,9,5
    C| 6, 7, 8, 5                   | 5,6,7,8                            |7,8,9,5
      

  7.   


     十分感谢!
    我的是用sql server,没有concat函数
    最终显示的是一个表格数据,没有逗号的.感觉第一行,估计在Sql语句中不好体现吧。 比如评分人A(是跨越4个列的,这个或许要在代码显示成体现)
    ===== ---- 评分人A ------------ |---- 评分人B -----------|---- 评分人B ------------
    被评分人|item1|item2|item3|item4 |item1,item2,item3,item4 |item1,item2,item3,item4 |
    A| 6| 8, 9, 7                   |5,6,7,8                             |7      8           9       5
    B| 8, 9, 4, 5                   |5,6,7,8                             |7,8,9,5
    C| 6, 7, 8, 5                   | 5,6,7,8                            |7,8,9,5

    sqlserver 2012里面有concat函数。
    你的版本没有的话,那就改一下
    SELECT 'A' 评分人,'A' 被评分人,6 item1, 8 item2,9 item3,7 item4
    into #t
    UNION ALL SELECT 'A','B',8, 9, 4, 5
    UNION ALL SELECT 'A','C',6, 7, 8, 5
    UNION ALL SELECT 'B','A',5, 6,  7,  8
    UNION ALL SELECT 'B','B',6, 9, 8, 5
    UNION ALL SELECT 'B','C',6, 7, 9, 5
    UNION ALL SELECT 'C','A',5, 6,  7,  8
    UNION ALL SELECT 'C','B',6, 9, 8, 5
    UNION ALL SELECT 'C','C',6, 7, 9, 5declare @str nvarchar(max)='';
    select @str =@str+N',MAX(case 评分人 when '''+评分人+N''' then Cast(item1 as varchar(20))+'',''+Cast(item2 as varchar(20))+'',''+Cast(item3 as varchar(20))+'',''+Cast(item4 as varchar(20)) else null end) AS score'+[评分人]
    from (select distinct [评分人] from  #t) t;select @str= N'select 被评分人'+ @str
    +N' from #t 
    GROUP BY 被评分人'Exec (@str)