SQL/LeetCode
LeetCode_3. Basic Aggregate Functions
JeoK
2025. 3. 31. 14:08
https://leetcode.com/studyplan/top-sql-50/
620. Not Boring Movies
문제 : 홀수번호 중 지루하지 않은 영화 추출
select *
from cinema
where id % 2 = 1 and description = 'boring'
order by rating
;
1251. Average Selling Price
문제 : 각 제품이 판매된 기간의 평균 판매 단가 구하기
- ifnull( 반환 값, null일 경우 대체 값 )
select p.product_id,
ifnull(round(sum(p.price * u.units) / sum(u,units), 2), 0) as average_price --단가계산, null은 0으로 대체
from prices p
left join unitssold u on p.product_id = u.product_id -- product_id가 일치하고,
and u.purchase_date between p.start_date and p.end_date -- 판매일이 가격 유효기간 내에 있는 경우만 join
group by p.product_id
;
1075. Project Employees I
문제 : 각 프로젝트에 대한 모든 직원의 평균 경력연수 구하기
select p.project_id, round(avg(e.experience_years), 2) as average_years
from project p
left join employee e on p.employee_id = e.employee_id
group by p.project_id
;
1633. Percentage of Users Attended a Contest
문제 : 각 대회에 참가한 유저 비율 구하기
Queries Quality of Percentage
문제 :
Monthly Transactions I
문제 :
Immediate Food Deilvery II
문제 :
Game Play Analysis Iv
문제 :