코테준비 | Second Highest Salary (의도적으로 null 값 출력하기)
·
SQL
☑️  176. Second Highest Salary[문제]Write a solution to find the second highest distinct salary from the Employee table. If there is no second highest salary, return null (return None in Pandas).두번째로 높은 연봉자 조회하기, 없다면 null 로 반환[문제 풀이]내 코드 - window & with 문WITH dnkt AS (SELECT * ,DENSE_RANK() OVER (ORDER BY salary DESC) as dnk ,count(id) OVER () AS total_cntsFROM employee), nullt AS (SELEC..
코테준비 | Patients With a Condition (문자열 추출 - 정규표현식 REGEXP , 특정문자기준 슬라이싱 - SUBSTRING_INDEX)
·
SQL
☑️  Patients With a Condition[문제]Write a solution to find the patient_id, patient_name, and conditions of the patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix.'DIAB1' 가 접두사인 값 모두 출력 [문제 풀이]코드1 - LIKESELECT *FROM PATIENTS WHERE conditions LIKE 'DIAB1%' OR conditions LIKE '% DIAB1% 코드2 - REGEXP SELECT *FROM PATIENTS WHERE conditions REGEXP '^DIAB1' OR conditi..
코테 준비 | Friend Requests II: Who Has the Most Friends / Investments in 2016 (union all / 중복값만 or 중복값이 아닌 행만 필터링 하기)
·
SQL
☑️  602. Friend Requests II: Who Has the Most Friends[문제]Write a solution to find the people who have the most friends and the most friends number.The test cases are generated so that only one person has the most friends.가장 많은 친구를 가진 사람과 그 수 조회하기[문제 풀이]내 코드 WITH total AS ( SELECT requester_id as id ,count(distinct accepter_id) as n FROM REQUESTACCEPTED GROUP BY requester_id UNIO..
코테 준비 | 리트코드 Rising Temperature/ Customer Who Visited but Did Not Make Any Transactions
·
SQL
197. Rising Temperature ▶ 문제 POINT :  전 일(yesterday) 값 가져오기[문제] Write a solution to find all dates' id with higher temperatures compared to its previous dates (yesterday).→ 어제 대비 높은 온도의 id 찾기 [조건] - 전일(yesterday) 값 컬럼 필요- 전일  ▶ 문제 해결 & 피드백 POINT : lag 윈도우 함수 or join 조건 활용하여 이전 값 가져오기[풀이 과정 1]1. 전일 값 가져오기 : `join` 으로 연결 join on 조건으로 전일자 값 연결 : `date_sub` 함수 활용where 절에서 대소 비교 id 출력 SELECT w1.idFRO..