본문 바로가기

MySQL

(9)
[해커랭크] [sql] SQL Project Planning SQL Project Planning | HackerRank SQL Project Planning | HackerRank Write a query to output the start and end dates of projects listed by the number of days it took to complete the project in ascending order. www.hackerrank.com 이번 문제는 어려워서 다른 분의 블로그를 참고하여 풀었습니다. [HackerRank SQL] SQL Project Planning (tistory.com) Sample Input Sample Output 2015-10-28 2015-10-29 2015-10-30 2015-10-31 2015-10-13 2..
[해커랭크] [sql] Ollivander's Inventory 오늘은 medium 문제 중 Ollivander's Inventory 를 풀어봤다. Harry Potter and his friends are at Ollivander's with Ron, finally replacing Charlie's old broken wand. Hermione decides the best way to choose is by determining the minimum number of gold galleons needed to buy each non-evil wand of high power and age. Write a query to print the id, age, coins_needed, and power of the wands that Ron's interested in..
[해커랭크] [sql] [medium] New Companies New Companies New Companies | HackerRank Find total number of employees. www.hackerrank.com 이번 문제는 계층에 따라 테이블이 있는 문제였다. Sample Input Company Table: Lead_Manager Table: Senior_Manager Table: Manager Table: Employee Table: Sample Output C1 Monika 1 2 1 2 C2 Samantha 1 1 2 2 c1(Monika), c2(samantha)에 따라 각 계층별로 개수를 출력하는 문제이다. SM2 같은 경우는 senior_manager 테이블에서 끝나기 때문에 Manager와 Employee에는 없다. 그래서 나는 Com..
[해커랭크] [SQL] The PADs 스터디 팀원들과 리트코드 무료문제를 다 풀었다! 이제 해커랭크로 고고 오늘 푼 문제: The PADS | HackerRank The PADS | HackerRank Query the name and abbreviated occupation for each person in OCCUPATIONS. www.hackerrank.com 헷갈렸던 점: 두개의 쿼리를 작성해야하는 문제인데 한 쿼리로 다 풀려고 했다가 헤맸다. 샘플 아웃풋 : Ashely(P) Christeen(P) Jane(A) Jenny(D) Julia(A) Ketty(P) Maria(A) Meera(S) Priya(S) Samantha(D) There are a total of 2 doctors. There are a total of 2 sin..
[leetcode] [MySQL] 176. Second Highest Salary https://leetcode.com/problems/second-highest-salary/submissions/ Second Highest Salary - LeetCode Second Highest Salary - Table: Employee +-------------+------+ | Column Name | Type | +-------------+------+ | id | int | | salary | int | +-------------+------+ id is the primary key column for this table. Each row of this table contains information about leetcode.com problem Write an SQL query to ..
[oracle] [mysql] group by 시 유의사항 출처: http://jason-heo.github.io/mysql/2014/03/05/char13-mysql-group-by-usage.html https://school.programmers.co.kr/questions/38703 GROUP BY 에서 SELECT할 수 있는 컬럼은 다음과 같다. GROUP BY에 나열된 컬럼 SUM(), COUNT() 같은 집계 함수(Aggregation Function)으로 한정된다. 그런데 oracle은 만약에 위에 해당하지 않은 컬럼(group by에 나열되지 않고, 집계함수가 아닌 컬럼)을 SELECT 하면 “not a GROUP BY expression” 이라는 오류가 뜬다. 하지만 mysql은 오류가 나지 않는다. group by 오류의 예시: 아래와 같이 ..
[프로그래머스 ] [sql] lv1. 12세 이하인 여자 환자 목록 출력하기 https://school.programmers.co.kr/learn/courses/30/lessons/132201 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr PATIENT테이블에서 12세 이하인 여자환자의 환자이름, 환자번호, 성별코드, 나이, 전화번호를 조회하는 SQL문을 작성해주세요. 이때 전화번호가 없는 경우, 'NONE'으로 출력시켜 주시고 결과는 나이를 기준으로 내림차순 정렬하고, 나이 같다면 환자이름을 기준으로 오름차순 정렬해주세요. MySQL IFNULL , IF , CASE WHEN 다양하게 사용 가능 SELECT PT_NAME, PT..
프로그래머스 [SQL] Lv1. 흉부외과 또는 일반외과 의사 목록 출력하기 https://school.programmers.co.kr/learn/courses/30/lessons/132203 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제| DOCTOR테이블에서 진료과가 흉부외과(CS)이거나 일반외과(GS)인 의사의 이름, 의사ID, 진료과, 고용일자를 조회하는 SQL문을 작성해주세요. 이때 결과는 고용일자를 기준으로 내림차순 정렬하고, 고용일자가 같다면 이름을 기준으로 오름차순 정렬해주세요. [1] MySQL #MYSQL SELECT DR_NAME ,DR_ID ,MCDP_CD ,DATE_FORMAT(HIRE_YMD,'%Y-..