经常遇到有某行数据需要转换成列来显示的情况,记下个简单例子:
select T.id,max(T.C17) as C17,max(T.C94) as C94 from (
select id ,(case ItemCode when '17' then ItemResult else '' end) C17,(case ItemCode when '94' then ItemResult else '' end) C94 from (select Id,ItemCode,ItemResult from DIS_CheckItemResult where PTYPE=1) TT
) T group by id