mysql数据库,纵向数据横向化问题 数据在数据库中如图1存储 要显示成图二
若以下回答无法解决问题,邀请你更新回答
2013-01-09
展开全部
SELECT
battery_id, test_id, tpm_id,
SUM (CASE WHEN data_nm = '0T' THEN data_val ELSE 0 END ) AS `0T`,
SUM (CASE WHEN data_nm = '1T' THEN data_val ELSE 0 END ) AS `1T`,
SUM (CASE WHEN data_nm = '2T' THEN data_val ELSE 0 END ) AS `2T`
FROM
表
GROUP BY
battery_id, test_id, tpm_id
battery_id, test_id, tpm_id,
SUM (CASE WHEN data_nm = '0T' THEN data_val ELSE 0 END ) AS `0T`,
SUM (CASE WHEN data_nm = '1T' THEN data_val ELSE 0 END ) AS `1T`,
SUM (CASE WHEN data_nm = '2T' THEN data_val ELSE 0 END ) AS `2T`
FROM
表
GROUP BY
battery_id, test_id, tpm_id
追问
0T、1T、和2T是动态的,可能还会有3T、4T、5T等等哦,在线等,
谢谢哦
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询