본문 바로가기
728x90

전체 글348

[리트코드] 180. Consecutive Numbers - MySQL https://leetcode.com/problems/consecutive-numbers/ Consecutive Numbers - LeetCode Can you solve this real interview question? Consecutive Numbers - Table: Logs +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | num | varchar | +-------------+---------+ id is the primary key for this table. id is an leetcode.com 문제 연속하는 3개의 num이 같은 num 출력하라 풀이 1 - JOIN 연속하는 .. 2023. 7. 6.
[해커랭크] The Report - MySQL https://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점보다 낮은 점수 학생의 이름은 원하지 않는다. Grade 내림차순으로 (학생이름, Grade, Marks) 출력 조건 8~10점 분포의 학생은 이름순으로 정렬 1~7점 분포의 학생은 Marks으로 정렬 + 이름은 NULL로 지정 풀이 Grades 테이블을 통해 각 학생의 Grade 구하기 SELECT * FROM Students AS s INNER JOIN Grades AS.. 2023. 7. 6.
[SQL] WITH 절 / WITH RECURSIVE 절 WITH 절 임시테이블 or 가상 테이블 반복되는 서브쿼리 블록을 하나의 WITH 절 블록으로 만들어서 사용 가능 한 번 실행할 쿼리문 내 정의하여 해당 쿼리 안에서만 실행 # 가상 테이블 만들기 WITH 이를 지칭할 테이블명(new) AS ( 서브쿼리 ) # 사용 SELECT new.id FROM new; WITH RECURSIVE 절 가상 테이블을 생성하면서 가상 테이블 자신의 값을 참조하여 값을 결정할 때 사용 -- 0~23 시간 컬럼 만들기 WITH RECURSIVE TIME_HOUR AS ( SELECT 0 AS H UNION SELECT H+1 FROM TIME_HOUR WHERE H < 23 ) 2023. 7. 6.
[해커랭크] Challenges - MySQL https://www.hackerrank.com/challenges/challenges/problem Challenges | HackerRank Print the total number of challenges created by hackers. www.hackerrank.com 문제 해커id, 이름, 각 학생이 만든 챌린지 수(challenges_created) 출력 challenges_created 내림차순, 해커id 오름차순 정렬 challenges_created가 같은 사람이 존재할 때 challenges_created가 최댓값이라면 출력 challenges_created가 최댓값이 아니라면 제외 풀이 CODE1 : 요구사항 1번, 2번 -- 출력 해커id, 이름, 각 학생이 만든 챌린지 수(ch.. 2023. 7. 6.
[리트코드] 196. Delete Duplicate Emails - MySQL https://leetcode.com/problems/delete-duplicate-emails/ Delete Duplicate Emails - LeetCode Can you solve this real interview question? Delete Duplicate Emails - Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | email | varchar | +-------------+---------+ id is the primary key column for this leetcode.com 문제 중복된 email 행 제거하면서 id가 가장 작은 행만 남겨라 풀.. 2023. 7. 6.
[리트코드] 627. Swap Salary - MySQL https://leetcode.com/problems/swap-salary/ Swap Salary - LeetCode Can you solve this real interview question? Swap Salary - Table: Salary +-------------+----------+ | Column Name | Type | +-------------+----------+ | id | int | | name | varchar | | sex | ENUM | | salary | int | +-------------+----------+ id is the primar leetcode.com 문제 SEX 컬럼의 값이 'f'면 'm'으로 / 'm'이면 'f'로 바꿔라 풀이 데이터를 수정하는 것이니 UPD.. 2023. 7. 5.
반응형