SELECT DISTINCT `user_id`
FROM `ticket`
WHERE `user_id` IN (SELECT `user_id` FROM `ticket` WHERE `type` = 2)
AND `user_id` IN (SELECT `user_id` FROM `ticket` WHERE `type` = 3)
AND `user_id` NOT IN (SELECT `user_id` FROM `ticket` WHERE `type` = 1)
AND `user_id` NOT IN (SELECT `user_id` FROM `ticket` WHERE `type` = 4)
SELECT `c`.`id`, `c`.`name`, `s`.`score`
FROM (
SELECT `cp`.`id_clan` AS `id_clan`,
SUM(`uc`.`health`) + SUM(`uc`.`power`)
+ SUM(`uc`.`agil`) + SUM(`uc`.`intell`) AS `score`
FROM `clan_part` AS `cp`
JOIN `users_combat` AS `uc` ON `uc`.`id_user` = `cp`.`id_user`
GROUP BY `cp`.`id_clan`
ORDER BY `score` DESC
LIMIT 0, 10
) AS `s`
JOIN `clan` AS `c` ON `c`.`id` = `s`.`id_clan`