您的位置:首页 > 博客中心 > 数据库 >

sql纵表转换成横表

时间:2022-03-14 04:08

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

数据库纵表数据

技术分享


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 


热门排行

今日推荐

热门手游