欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

将纵表转换为横表

程序员文章站 2022-03-09 10:35:12
...

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

数据库纵表数据


将纵表转换为横表
 转换后


将纵表转换为横表
 

转换代码

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