해커랭크

    [해커랭크/SQL] Top Competitors

    www.hackerrank.com/challenges/full-score/problem Top Competitors | HackerRank Query a list of top-scoring hackers. www.hackerrank.com 문제 요약 두 개 이상의 문제를 푼 해커들의 hacker_id와 name을 조회하는 문제입니다. 문제 수를 기준으로 내림차순 하고, 문제 수가 같은 경우 hacker_id를 기준으로 오름차순 정답 코드 테이블을 조인을 이용해서 알맞게 연결하면 어려운 문제는 아니라고 생각합니다. 처음엔 테이블 연결하는 걸로 많이 해맸네여........ select s.hacker_id, h.name from submissions s join challenges c on (s.challe..

    [해커랭크/SQL] New Companies

    www.hackerrank.com/challenges/the-company/problem New Companies | HackerRank Find total number of employees. www.hackerrank.com 문제 요약 회사코드, 설립자, 각 계급별 직원수를 회사코드를 기준으로 오름차순 하여 조회하는 문제 (단, 회사코드는 문자열임 -> ex) C1 -> C11 -> C2 ... 이런 식으로 정렬) 정답 코드 조인만 해서 정렬하면 되는 문제라서 정말 간단한 문제인데 문제를 잘못 이해해서 엄청 해맸네여 ㅋㅋ... C1 -> C2 -> C3처럼 숫자 기준으로 정렬하는 문제라고 생각해서 30분을 날렸습니다. 중복 값이 있을 수도 있기 때문에 distinct를 이용해서 중복 값을 없애준 co..

    [MySQL/해커랭크] The Report

    www.hackerrank.com/challenges/the-report/problem The Report | HackerRank Write a query to generate a report containing three columns: Name, Grade and Mark. www.hackerrank.com 문제를 간단히 요약해보면 등급 순, 이름순으로 학생들의 이름, 등급, 점수를 조회하는 기초적인 조인 문제입니다. 등급이 8미만인 학생들의 이름은 NULL 처리를 해줘야 하는 조건이 있습니다. 정답 코드 select if(g.grade < 8, null, s.name), g.grade, s.marks from students s join grades g on (s.marks between g.min..

    [MySQL/해커링크] Placements

    www.hackerrank.com/challenges/placements/problem Placements | HackerRank Write a query to output the names of those students whose best friends got offered a higher salary than them. www.hackerrank.com SQL연습도 하고 MySQL 문법도 익힐겸 SQL 문제를 풀어보려고 합니다 :) 이 문제를 간단하게 설명하자면 본인의 월급보다 친구의 월급이 높을 때 그 친구의 이름을 조회하는 문제입니다. 저는 2가지 방식으로 풀었습니다. 1. JOIN만 사용한 방식 SELECT s.name from STUDENTS s JOIN FRIENDS f ON (s.id =..

    [MySQL/해커랭크] Symmetric Pairs

    www.hackerrank.com/challenges/symmetric-pairs/problem Symmetric Pairs | HackerRank Write a query to output all symmetric pairs in ascending order by the value of X. www.hackerrank.com JOIN을 이용한 간단한 문제입니다. 문제의 조건은 X1 = Y2 && X2 = Y1 이여야 합니다. select f1.x, f1.y from functions f1 join functions f2 on (f1.x = f2.y and f2.x = f1.y) group by f1.x, f1.y having count(*) > 1 or f1.x < f1.y order by f1.x