select
mu.merchant_id,
mu.merchant_name,
a.total_sales_amount,
b.total_refund_amount,
c.average_satisfaction_score
from
merchants_underline as mu
left join (
select
merchant_id,
sum(sale_amount) as total_sales_amount
from
sales_underline
group by
merchant_id
)a
on
mu.merchant_id = a.merchant_id
left join (
select
merchant_id,
sum(refund_amount) as total_refund_amount
from
refunds_underline
group by
merchant_id
)b
on
mu.merchant_id = b.merchant_id
left join (
select
merchant_id,
round(avg(satisfaction_score),2) as average_satisfaction_score
from
satisfaction_underline
group by
merchant_id
)c
on
mu.merchant_id = c.merchant_id
order by
mu.merchant_id