[技术备案]SqlSever字符串行列转换

第一步:

设计表格MaxMin,结构如下:

[技术备案]SqlSever字符串行列转换

里面填满了测试数据:

[技术备案]SqlSever字符串行列转换

第二步:

写测试代码:

select PlayerSID,
max(case RaterName when pw01 then MaxSign1+MinSign1+MaxSign2+MinSign2  else ‘‘ end) as pw01,
max(case RaterName when pw02 then MaxSign1+MinSign1+MaxSign2+MinSign2  else ‘‘ end) as pw02,
max(case RaterName when pw03 then MaxSign1+MinSign1+MaxSign2+MinSign2  else ‘‘ end) as pw03,
max(case RaterName when pw04 then MaxSign1+MinSign1+MaxSign2+MinSign2  else ‘‘ end) as pw04,
max(case RaterName when pw05 then MaxSign1+MinSign1+MaxSign2+MinSign2  else ‘‘ end) as pw05
FROM  MaxMin
group by PlayerSID

最新效果:

[技术备案]SqlSever字符串行列转换

技术切记:

表格数据初始为Null时,会出现异常。初始化,为空时,初始化为空字符串 ‘‘

[技术备案]SqlSever字符串行列转换

上一篇:MongoDB副本集replica set(五)--故障排查


下一篇:mysql基础复习