mysql - How to calculate from 2 tables in SQL -


how create query join table , b condition a.salary * b.rate

table --------------------- customerid     salary a1              100 a2              200 a3              300  table b --------------------- customerid     rate a1              2 a2              3 a3              4 

my expect result.

---------------------  customerid     salary  a1              200  a2              600  a3              1200 

select t1.customerid,        coalesce(t1.salary * t2.rate, 'na') salary tablea t1 left join tableb t2     on t1.customerid = t2.customerid 

i used coalesce when computing effective salaries in case either salary amount or rate null customer.

demo here:

sqlfiddle


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -