SELECT c.name category,COUNT(t.id)/30 daily_sales_rate FROM categories c JOIN products p ON c.id=p.category_id JOIN transaction_sell_lines tsl ON p.id=tsl.product_id JOIN transactions t ON tsl.transaction_id=t.id WHERE t.type="sell" AND t.transaction_date>=DATE_SUB(CURRENT_DATE,INTERVAL 30 DAY) GROUP BY c.id,c.name ORDER BY daily_sales_rate DESC;