求列转行sql
表的结构
表头 kpi_id dev_id value g_group
020102 sb1 192.186.1.1 2
020101 sb1 80 2
020102 sb1 192.186.1.2 1
020101 sb1 8080 1
需要展现的数据是
物理端口 IP地址
80 192.186.1.1
8080 192.186.1.2
原sql:
SELECT SUM(DECODE(T.KPI_NAME, '物理端口', nvl(S.VALUE, 0))) AS "020101",
SUM(DECODE(T.KPI_NAME, 'IP地址', nvl(S.VALUE, 0))) AS "020102",
S.G_GROUP as KPI_GROUPS
FROM S_DEVICEKPI S, S_KPIMSG T
WHERE S.KPI_ID = T.KPI_ID
AND S.DEV_ID = 'sb1'
GROUP BY S.G_GROUP
但是因为value 是字符串sum不能用 ,求大神没出招
------解决方案--------------------sum不能用,就用max嘛