SQL:行列转换-操作查询结果case when then else end用法举例
SQL:行列转换
现在的结果:
想要的结果:
把现在的结果,每取4列放在一行。
select
max(case QUESTIONNO when 'TJBGSAB1' then QUESTIONANSWER end),
max(case QUESTIONNO when 'TJBGSAB2' then QUESTIONANSWER end),
max(case QUESTIONNO when 'TJBGSAB3' then QUESTIONANSWER end),
max(case QUESTIONNO when 'TJBGSAB4' then QUESTIONANSWER end)
from LCREPORTQUESTIONNAIRE
where CONTNO = '00000000001114'
and idno = '0000055911'
and QUEMODULECODE ='TJBGSA'
and QUESUBMODULECODE like 'B%'
group by QUESUBMODULECODE;