日期:2014-05-16 浏览次数:21115 次
select code,rc,
    sum(iif([month]='month1', result1,0) as month1,
    sum(iif([month]='month2', result1,0) as month2
from(
select code,'result1' as rc,[month],result1 from 表
union all
select code,'result2' as rc,[month],result2 from 表
union all
select code,'result3' as rc,[month],result3 from 表
) 
group by code,rc
------解决方案--------------------
transform max(result1)
select code,bz from  
查询3  group by code,bz
pivot month
查询3  
SELECT code,month,result1,'r1' as bz  from tt5
union all
SELECT code,month,result2,'r2' from tt5
UNION ALL SELECT code,month,result3,'r3' from tt5;