목록데이터베이스 (39)
개발은 처음이라 개발새발
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()함수까지 곁들인 퀴즈입니다...
https://leetcode.com/problems/employees-earning-more-than-their-managers/description/ Employees Earning More Than Their Managers - LeetCode Can you solve this real interview question? Employees Earning More Than Their Managers - Table: Employee +-------------+---------+ | Column Name | Type | +-------------+---------+ | id | int | | name | varchar | | salary | int | | managerId | int | +------ l..
https://www.hackerrank.com/challenges/average-population-of-each-continent/problem?h_r=internal-search Average Population of Each Continent | HackerRank Query the names of all continents and their respective city populations, rounded down to the nearest integer. www.hackerrank.com 오늘은 JOIN과 관련된 해커랭크의 퀴즈를 들고왔습니다. 문제는 city, country라는 두개의 테이블이 있고 두 테이블을 조인 시켜 country 테이블에 있는 continent를 기준으로 city 테이..