with t1 as( select p.category, count(distinct oi.order_id) as orders_cnt, count(distinct o.buyer_id) as buyers_cnt, sum(qty) as items_qty, sum(qty*price) as revenue, round(sum(qty*price)/count(distinct oi.order_id),2) as avg_order_value from product p left join order_items oi using(product_id) left ...