"Is it query which needs to be optimized ?" - кратко об оптимизации "GROUP BY", "COUNT" и "ORDER BY" в MySQL.