1

I'm using the below command to find the sum of records from 8 columns but getting null in the O/P as shown below.

Command part 1

command part 2

Output

How can this be fixed?

leftjoin
  • 36,950
  • 8
  • 57
  • 116
Inban
  • 33
  • 6
  • I'm getting the output using single record ('H' for example) in the command./ – Inban Nov 09 '19 at 07:07
  • Please do never post code or data examples as pictures if you really want help and do not want your question down-voted – leftjoin Nov 09 '19 at 07:37

1 Answers1

1

Yes, the thing is NULL + something results NULL. To solve this, wrap each sum() in the NVL(sum(),0), so if some particular sum() is NULL, it is converted to 0 and the whole total will be not null:

nvl(sum(case when col1='something' then 1 else 0 end),0)+ ...

Or always use else 0, like in the first expression (H).

Wrapping with NVL() will solve the problem even if column comes from the join and the rows are absent and sum is NULL.

leftjoin
  • 36,950
  • 8
  • 57
  • 116