570. Managers with at least 5 direct reports
https://leetcode.com/problems/managers-with-at-least-5-direct-reports/description/
#구할 값: name
# 조건절에서 managerId가 5번 이상 언급되는 값을 찾아서 집계해준다.
select name
from Employee
where id in
(select managerId
from Employee
group by managerId
having count(*) >= 5)
1934. Confirmation Rate
https://leetcode.com/problems/confirmation-rate/description/
각 사용자의 확인율을 구하고, 소수 2째자리에서 반올림한다.
확인율은 'confirmed'된 확인 메시지의 평균
select s.user_id,
round(avg(if(c.action="confirmed",1,0)),2) as confirmation_rate
from Signups as s left join Confirmations as c on s.user_id= c.user_id
group by user_id;
620. Not Boring Movies
https://leetcode.com/problems/not-boring-movies/description/
Cinema 테이블에서 홀수로 된 id 값, description이 boring으로 응답한 관객을 찾으면 되는 문제
select *
from Cinema
where mod(id,2) = 1 and description <> 'boring'
order by rating desc
✅MOD함수
홀수 행 검색
select *
from table
where mod(number,2) = 1
짝수 행 검색
select *
from table
where mod(number, 2) = 0
'DATA > SQL' 카테고리의 다른 글
SQL풀이: Leetcode 1661. Average Time of Process per Machine (0) | 2025.01.15 |
---|---|
SQL: LAG 함수 활용하여 현재 데이터와 이전 데이터를 비교 (1) | 2025.01.09 |
241211 SQL 코드카타(조건에 맞는 사용자 정보 조회하기, 조건에 부합하는 중고거래 상태 조회하기, 취소되지 않은 진료 예약 조회하기) (3) | 2024.12.11 |
SQL 코드카타 풀이(없어진 기록 찾기, 과일로 만든 아이스크림 고르기, 재구매가 일어난 상품과 회원 구하기) (1) | 2024.12.10 |