将纵表转换为横表

数据库中 将一张纵表转换为一张横表

数据库纵表数据



 转换后



 

转换代码

select cardid,
max(case t.projectcode when 'IA-002' then t.result  end) as ht,
max(case t.projectcode when 'IA-003' then t.result end) as wt,
max(case t.projectcode when 'IA-005' then t.result  end) as bmi,
max(case t.projectcode when 'IA-000' then t.result  end) as xl,
max(case t.projectcode when 'CG-005' then t.result end) as xybhd,
max(case t.projectcode when 'CD-002' then t.result  end) as kfxt,
max(case t.projectcode when 'CD-003' then t.result  end) as chxt,
max(case t.projectcode when 'IA-014' then t.result end) as xy,
max(case t.projectcode when 'JA-001' then t.result  end) as xd,datetime 
from projectresultinfo t group by t.cardid  order by datetime desc 

猜你喜欢

转载自lqis.iteye.com/blog/2154947