I have a table A with columns (a, b) and a table B with columns (b, c). I want to do the following:
STEP 1: do a A LEFT OUTER JOIN B ON A.b = B.b
STEP 2: convert all c = NULL in the Joined table to c = <default_value>
STEP 3: SUM(A.a * B.c) over the table I get after STEP 2
Is there a quick way to do this in one compound statement?
Thanks!
You can do the three steps in one query, first
LEFT OUTER JOINand useIFNULLto set theNULLvalues to a default value, then useSUM:SQL Fiddle Demo:
STEP 1, STEP 2.
STEP 3.