목록mysql (42)
개발은 처음이라 개발새발
https://www.hackerrank.com/challenges/the-report/problem?h_r=internal-search The Report | HackerRank Write a query to generate a report containing three columns: Name, Grade and Mark. www.hackerrank.com 이번에는 join 구문에서 between절을 활용하는 퀴즈를 풀어보려고 합니다. 흔히 join 구문에서 두 테이블을 매칭 시킬 때 on을 적고 그안에 각각의 테이블에서 매칭 시킬 수 있는 컬럼을 "A.컬럼 = B.컬럼 " 이런식으로 적는게 기본인데요. 하지만 모든 상황과 테이블들이 이 같은 구문으로 해결될순 없겠죠. 그렇기에 하나의 구문에서 어떻게..
https://www.hackerrank.com/challenges/challenges/problem?h_r=internal-search Challenges | HackerRank Print the total number of challenges created by hackers. www.hackerrank.com 이번 문제는 손이 많이 가는 서브쿼리 퀴즈인데요. 우선 예제를 살펴보겠습니다. 네 문제는 Hackers와 Challenges라는 두 테이블을 가지고 문제를 푸는 것입니다. 이 문제가 어려운 이유는 조건인데요. 조건을 간단하게 요약하면 다음과 같습니다. ###조건 조건1. hacker_id 별 name과 challenges의 개수를 구해라 조건2. hacker_id 별 최대 challenges를..
https://leetcode.com/problems/department-highest-salary/ Department Highest Salary - LeetCode Can you solve this real interview question? Department Highest Salary - Table: Employee +--------------+---------+ | Column Name | Type | +--------------+---------+ | id | int | | name | varchar | | salary | int | | departmentId | int | +--------------+--- leetcode.com Input: Employee table: +----+-----..
https://www.hackerrank.com/challenges/earnings-of-employees/problem?h_r=internal-search Top Earners | HackerRank Find the maximum amount of money earned by any employee, as well as the number of top earners (people who have earned this amount). www.hackerrank.com 이번에는 해커랭크의 서브쿼리 퀴즈를 풀어보겠습니다. 문제는 employee라는 테이블이 있고 그안에 아이디와, 이름, 개월수, salary의 컬럼으로 형성돼 있는데요. 문제는 개월수(months)와 salary를 곱한 값이 최대 몇이고 이 ..
서브쿼리는 SELECT , FROM ,WHERE 절까지 곳곳에서 많이 사용합니다. 저는 개인적으로 실무를 하면서 서브쿼리를 자주 사용하는데요. 이유는 여러가지가 있겠지만 대표적인 이유로는 특정 테이블의 하나의 조건 혹은 하나의 컬럼만 필요한데 굳이 JOIN을 하게 되면 여러모로 불편한 점이 생기기 때문입니다. 1. SELECT절에 사용하는 서브쿼리 - SELECT절에서 사용하는 서브쿼리를 스칼라 쿼리라고 하는데요. SELECT 절에서 사용하는 서브쿼리의 특징으로는 불러오는 값을 하나만 지정해야 한다는 점입니다. SELECT절 서브쿼리는 나중에 따로 더 다뤄보도록하겠습니다. 2. FROM절에 사용하는 서브쿼리 https://data-so-hard.tistory.com/78 서브쿼리를 활용한 DELETE [..
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 이번에는 DELETE 구문 연습을 가장한 서브쿼리 퀴즈를 한번 풀어보겠..
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 이번 시간에는 DML 명령어 중 UPDATE를 활용한 퀴즈를 풀어보려고합니다. 문제를 보겠습니다. Input: ..
DML (Data Manipulation Language) 이란, 데이터베이스에 입력된 데이터를 조회, 수정, 삭제 등의 역할을 하는 언어로 직역하면, 데이터 조작어입니다. DML의 명령어로는 SELECT, INSERT, UPDATE,DELETE가 있습니다. 1. INSERT - 없는 데이터를 넣을 때 1-1. 테이블에 데이터를 넣을 때 INSERT INTO 테이블명 VALUES (VALUE_LIST); _________________________________________________ EX) INSTER INTO Salary VALUES('1','A','250','2020-03-31'); 1-2. 특정 컬럼에만 데이터를 넣을 때 INSERT INTO 테이블명 (COLUMN _LIST) VALUES..
https://www.hackerrank.com/challenges/symmetric-pairs/problem?h_r=internal-search Symmetric Pairs | HackerRank Write a query to output all symmetric pairs in ascending order by the value of X. www.hackerrank.com 문제를 살펴보면 두가지 경우의 해당하는 x,y를 찾아야 합니다. 첫번째는 x와 y가 같은 로우가 2개이상일 때, 두번째는 x와 y가 교차로 다른 로우와 같을 때 y가 큰 쪽을 찾아야 합니다. 이렇게 서로 다른 조건을 가로로 붙이지 않고 세로로 붙일 때 UNION 함수를 사용합니다. 그렇다면 첫번째 조건부터 쿼리를 작성해보겠습니다. ..
https://leetcode.com/problems/rising-temperature/ Rising Temperature - LeetCode Can you solve this real interview question? Rising Temperature - Table: Weather +---------------+---------+ | Column Name | Type | +---------------+---------+ | id | int | | recordDate | date | | temperature | int | +---------------+---------+ id is the pr leetcode.com 이번 퀴즈는 Self Join뿐만 아니라 DATE_ADD()함수까지 곁들인 퀴즈입니다...