我目前正在努力让它发挥作用。
SELECT Y, SUM(N) AS sumDK, NULL AS sumFI, NULL AS sumNO, NULL AS sumSE
FROM stat
WHERE (C = 'Denmark')
GROUP BY Y
UNION ALL
SELECT Y, NULL AS sumDK, SUM(N) AS sumFI, NULL AS sumNO, NULL AS sumSE
FROM stat
WHERE (C = 'Finland')
GROUP BY Y
UNION ALL
SELECT Y, NULL AS sumDK, NULL AS sumFI, SUM(N) AS sumNO, NULL AS sumSE
FROM stat
WHERE (C = 'Norway')
GROUP BY Y
UNION ALL
SELECT Y, NULL AS sumDK, NULL AS sumFI, NULL AS sumNO, SUM(N) AS sumSE
FROM stat
WHERE (C = 'Sweden')
GROUP BY Y
这个查询给了我一个像这样的矩阵:
Y | sumDK | sumFI | sumNO | sumSE
----------------------------------
2011| 25 | NULL | NULL | NULL
2012| 5 | NULL | NULL | NULL
2011| NULL | 18 | NULL |NULL
2012| NULL | 5 | NULL |NULL
......
如何执行只返回字段 NOT NULL 的查询?提前致谢!