I am trying to make a rather complicated SELECT calculation, which I will generalize:
- The main query is a wildcard for a table
- In one subquery, there are
COUNT() all elements based on the condition (this works fine) - In another subquery, there is the
SUM() number of numbers in the column based on another condition. This also works correctly, except when the records do not meet the conditions, returns NULL .
At first, I wanted to add two subqueries, something like (subquery1)+(subquery2) AS total , which works fine if subquery2 is not equal to zero, in which case total becomes zero, regardless of the result of the result of subquery1. My second thought was to try to create a third column that was supposed to calculate two subqueries (i.e. (subquery1) AS count1, (subquery2) AS count2, count1+count2 AS total ), but I donβt think it is possible compute two calculated columns, and even if that were the case, I feel similarly to the same problem.
Does anyone have an elegant solution to this problem beyond getting two subquery values ββand summing them in my program?
Thanks!
Jason source share