Sum if all rows are not null else return null in MySQL?
Answers
Answered by
0
You can achieve that with:
SELECT x, SUM(value) FROM t GROUP BY x HAVING COUNT(value)=COUNT(*)
This will work following way: group values in normal way, but then compare entire count (so * points to that) with column count (which won't include NULL-s). If they are not equal, then there are NULL's and value shouldn't be included.
Similar questions