본문 바로가기

Algorithm/MySQL

(75)
[LeetCode] 184. Department Highest Salary (MySQL) 문제 employee테이블은 모든 직원들을 가지고 있다 모든 직원들은 id, salary, departmentId를 갖고있다 Department테이블은 회사의 모든 부서들을 갖고있다 각각의 부서에서 가장 높은 월급을 받는 직원들을 조회해라 코드 INNER JOIN + SUBQUERY 1. 직원별 각 부서 이름이 필요하므로 Employee 테이블과 Department 테이블 조인 SELECT * FROM Employee e INNER JOIN Department d ON e.DepartmentId = d.Id 2. group by를 해줘서 부서별 max 값 확인하기 SELECT d.name as Department, MAX(e.salary) as Salary FROM Employee e INNER JOIN..
[해커랭크(HackerRank)] The Report (MySQL) 문제 You are given two tables: Students and Grades. Students contains three columns ID, Name and Marks. Grades contains the following data: Ketty gives Eve a task to generate a report containing three columns: Name, Grade and Mark. Ketty doesn't want the NAMES of those students who received a grade lower than 8. The report must be in descending order by grade -- i.e. higher grades are entered firs..
[LeetCode] 175. Combine Two Tables (MySQL) 문제 사용자에 대한 주소가 있는지 여부에 관계없이 Person테이블에 있는 각각의 사용자 개인의 정보를 출력해라 코드 SELECT a.firstName, a.lastName, b.city, b.state FROM Person a LEFT JOIN Address b ON a.personId = b.personId 사용자에 대한 주소에 관계없이 출력하라고 했기 때문에 Person테이블을 기준으로 left join 하기 Address 테이블에 대한 데이터가 null이어도 상관없다는 말 출처
[해커랭크(HackerRank)] Top Competitors (MySQL) 문제 Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge. Order your output in descending order by the total number of challenges in which the hacker earned a full score. If more than one hacker received full scores in same number..