I have a table in this format
COL1 COL2 COL3
A NULL 4
A NULL 4
A VAL1 4
A VAL2 4
A VAL3 4
B NULL 5
B VAL1 6
I need to output the output as follows:
COL1 TOTAL VALID
A 20 12
B 11 6
My question is: how do I get the "VALID" column - it should do the sum of col3 only if col2 is not null.
I was able to get the "TOTAL" field correctly using the SUM and group by clauses. But how to calculate the "VALID" column?
Any ideas? Many thanks!
source
share