select reg.physical_num as 唯一编号
,
max(case 字段 when 内容 then 结果 else '' end) '抗HAV-IgM'
max(case res.project_name when '伤寒或副伤寒(沙门氏)' then res.project_result else '' end ) '伤寒或副伤寒'
from 表A inner join 表B on 表A.id=表B.person_id where reg.id=1 group by 唯一编号
示例:
select reg.physical_num,reg.person_name,reg.sex,reg.person_age,
max(case res.project_name when '抗HAV-IgM' then res.project_result else '' end) '抗HAV-IgM',
max(case res.project_name when '抗HEV-IgM' then res.project_result else '' end) '抗HEV-IgM',
max(case res.project_name when '痢疾杆菌(志贺氏)' then res.project_result else '' end) '痢疾杆菌',
max(case res.project_name when '伤寒或副伤寒(沙门氏)' then res.project_result else '' end ) '伤寒或副伤寒'
from professionalExam_register reg inner join professionalExam_project_result res on reg.id=res.person_id where reg.id=1 group by reg.physical_num,reg.person_name,reg.sex,reg.person_age
转载于:https://my.oschina.net/u/2242194/blog/632412