SELECT p.name,vld.qty_available current_stock,(tsl.unit_price_inc_tax-tsl.unit_price_before_discount)/tsl.unit_price_before_discount*100 margin_percentage,AVG(tsl.quantity) avg_order_size FROM products p LEFT JOIN variation_location_details vld ON p.id=vld.product_id LEFT JOIN transaction_sell_lines tsl ON p.id=tsl.product_id WHERE p.enable_stock=1 GROUP BY p.id,p.name,vld.qty_available,margin_percentage ORDER BY margin_percentage DESC;