SELECT p.name,MONTH(t.transaction_date) month,AVG(vld.qty_available) avg_stock_level,SUM(tsl.quantity) monthly_sales FROM products p JOIN transaction_sell_lines tsl ON p.id=tsl.product_id JOIN transactions t ON tsl.transaction_id=t.id LEFT JOIN variation_location_details vld ON p.id=vld.product_id WHERE t.type="sell" AND p.enable_stock=1 GROUP BY p.id,p.name,MONTH(t.transaction_date) ORDER BY p.name,month;