Fixed mysql analysis query