select max(case 类别 when '电子类' then 电压 end) as 电子类电压
      ,max(case 类别 when '电子类' then 长度 end) as 电子类长度
      ,max(case 类别 when '电子类' then 颜色 end) as 电子类颜色
      ,max(case 类别 when '电子类' then 容量 end) as 电子类容量
      ,max(case 类别 when '建材类' then 电压 end) as 建材类电压
      ,max(case 类别 when '建材类' then 长度 end) as 建材类长度
      ,max(case 类别 when '建材类' then 颜色 end) as 建材类颜色
      ,max(case 类别 when '建材类' then 容量 end) as 建材类容量
      ,max(case 类别 when '日用类' then 电压 end) as 日用类电压
      ,max(case 类别 when '日用类' then 长度 end) as 日用类长度
      ,max(case 类别 when '日用类' then 颜色 end) as 日用类颜色
      ,max(case 类别 when '日用类' then 容量 end) as 日用类容量
from(
select a.类别,b.电压,b.长度,b.颜色,b.容量 from Q_Category a,Item b
  where a.PKID=b.类别PKID
) aa

解决方案 »

  1.   

    如果你的类别不定,就用动态生成SQL的方法,不过,表的列数是有限制的,你要注意
      

  2.   

    zjcxc(邹建) 可能没有理解我的意思
    我是希望把竖表转成横表
    而不是取各列的最大 值
      

  3.   

    我的意思与邹建兄差不多,不过我不知道为什么要用max,去掉max应该可以
      

  4.   

    对,可以不用MAX,因为PKID在两个表中都没有重复
    是一对一的关系