SELECT p.name,vld.qty_available current_stock,v.default_purchase_price unit_value,SUM(tsl.quantity) monthly_sales FROM products p JOIN variations v ON p.id=v.product_id LEFT JOIN variation_location_details vld ON p.id=vld.product_id LEFT JOIN transaction_sell_lines tsl ON p.id=tsl.product_id LEFT JOIN transactions t ON tsl.transaction_id=t.id AND t.transaction_date>=DATE_SUB(CURRENT_DATE,INTERVAL 30 DAY) WHERE t.type="sell" GROUP BY p.id,p.name,vld.qty_available,v.default_purchase_price ORDER BY unit_value DESC;