with
t1 as(
select
product_line,
region,
channel_id,
channel_name,
sum(sale_amount) as total_sale_amount,
count(product_id) as total_sale_quantity
from
sales_data
left join oppo_products using(product_id)
left join sales_channels using(channel_id)
group by
product_line,
region,
channel_id,
channel_name
)
select
product_line,
region,
channel_name,
total_sale_amount,
total_sale_quantity
from
t1
order by
product_line,
channel_id

京公网安备 11010502036488号