SELECT p.name,vld.qty_available current_stock,MIN(daily_sales.quantity) min_daily_sales,AVG(daily_sales.quantity) avg_daily_sales FROM products p LEFT JOIN variation_location_details vld ON p.id=vld.product_id LEFT JOIN (SELECT product_id,DATE(transaction_date) date,SUM(quantity) quantity FROM transaction_sell_lines tsl JOIN transactions t ON tsl.transaction_id=t.id WHERE t.type="sell" GROUP BY product_id,DATE(transaction_date)) daily_sales ON p.id=daily_sales.product_id WHERE p.enable_stock=1 GROUP BY p.id,p.name,vld.qty_available ORDER BY avg_daily_sales DESC;