SELECT p.name,COUNT(t.id) recent_sales,SUM(tsl.quantity) recent_units FROM products p 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 p.id,p.name ORDER BY recent_sales DESC;