You are viewing a single comment's thread. Return to all comments →
MySQL:
WITH top_challenges AS ( -- Objetivo: Contar la cantidad de retos creados por cada hacker (incluye hackers con 0 retos) SELECT hac.hacker_id, hac.name, COUNT(cha.challenge_id) AS quantity_challenge FROM hackers hac LEFT JOIN challenges cha ON hac.hacker_id = cha.hacker_id GROUP BY hac.hacker_id, hac.name ), mark AS ( -- Objetivo: Para cada hacker, calcular: -- quantity_equal_challenges: cuantos hackers tienen el mismo numero de retos -- max_quantity_challenge: el maximo numero de retos creado por cualquier hacker SELECT *, COUNT(*) OVER (PARTITION BY quantity_challenge) AS quantity_equal_challenges, MAX(quantity_challenge) OVER() AS max_quantity_challenge FROM top_challenges ) -- Filtra hackers que: -- tienen el maximo numero de retos, o -- tienen un numero unico de retos (sin empates) SELECT hacker_id, name, quantity_challenge FROM mark WHERE quantity_equal_challenges = 1 OR quantity_challenge = max_quantity_challenge ORDER BY quantity_challenge DESC, hacker_id ASC;
Seems like cookies are disabled on this browser, please enable them to open this website
Challenges
You are viewing a single comment's thread. Return to all comments →
MySQL: