1

I want to add to query but the other query sometimes the value is NULL

SELECT (a.column1+b.column2)/2 from (SELECT COUNT(column1) from table 1) a,
                                    (SELECT COUNT(column2) from table 2) b

The results of these query is like

(26248+NULL)/2 which gives NULL as a result

What result I want supposed to be 13124.

Is there anyway I can make this happen?

1 Answer 1

2

You can use coalesce

 SELECT  (coalesce(a.column1,0)+ coalesce(b.column2,0))/2

COALESCE method return the first non-null parameter . so if b.column2 is null then it will return 0 .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.