首页 > 代码库 > sql纵表转换成横表

sql纵表转换成横表

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

数据库纵表数据

技术分享


sql语句如下

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 


sql纵表转换成横表