Sunday, 15 May 2011

sql - Compound mysql Select After outer join -



sql - Compound mysql Select After outer join -

i have table columns (a, b) , table b columns (b, c). want following:

step 1: left outer bring together b on a.b = b.b step 2: convert c = null in joined table c = <default_value> step 3: sum(a.a * b.c) on table after step 2

is there quick way in 1 compound statement?

thanks!

you can 3 steps in 1 query, first left outer join , utilize ifnull set null values default value, utilize sum:

select sum(a.a + ifnull(b.c, <default_value>)) left outer bring together b on a.b = b.b;

sql fiddle demo:

step 1, step 2.

step 3.

mysql sql join left-join outer-join

No comments:

Post a Comment