with t1 as ( select cs.shop_id, cs.shop_name, cs.city, o.product_name as top_product, product_revenue, p.customer_name as top_customer, customer_quantity, first_purchase_date from coffee_shops cs join lateral ( select product_name, sum(quantity * unit_price) as product_revenue from order_details od ...