如何才能实现基于两列联合的GROUP BY
?任一列中都可能有NULL
个值。有点像(显然这不起作用):
SELECT a.val, b.val
FROM a
LEFT JOIN b on a.id = b.id
GROUP BY UNION(a.val, b.val)
结果如:
a.val | b.val
-----------
1 1
2 2
NULL 3
4 NULL
5 5
谢谢!
答案 0 :(得分:1)
为什么不能使用NVL
SELECT NVL(a.val, b.val) FROM a LEFT JOIN b on a.id = b.id
GROUP BY NVL(a.val, b.val)