프로그래머스 SQL 고득점 키트 문제 6개(22년 10월 12일 기준) 문제풀이 기록
엥 오늘 보니까 join 파트에 2문제가 추가적으로 업데이트 되어 있다...?!
select member_profile.member_name, review_text, substr(review_date,1,10) as review_date
from rest_review join member_profile on member_profile.member_id = rest_review.member_id
where rest_review.member_id = (
select member_id
from rest_review
group by member_id
having count(member_id)
order by count(member_id) desc limit 1
)
order by review_date asc
select food_product.product_id, product_name, sum(price * amount)as total_sales
from food_product join food_order on food_product.product_id = food_order.product_id
where year(produce_date) = 2022 and month(produce_date) = 5
group by product_id
order by total_sales desc, product_id asc
select animal_outs.animal_id, animal_outs.name
from animal_outs left join animal_ins on animal_outs.animal_id = animal_ins.animal_id
where animal_ins.animal_id is null
on
외래키가 필수select animal_ins.animal_id, animal_ins.name
from animal_ins join animal_outs on animal_ins.animal_id = animal_outs.animal_id
where animal_ins.datetime > animal_outs.datetime
order by animal_ins.datetime asc
select animal_ins.name, animal_ins.datetime
from animal_ins left join animal_outs on animal_ins.animal_id = animal_outs.animal_id
where animal_outs.datetime is null
order by animal_ins.datetime asc limit 3
select animal_outs.animal_id, animal_outs.animal_type, animal_outs.name
from animal_outs left join animal_ins on animal_outs.animal_id = animal_ins.animal_id
where substr(animal_ins.sex_upon_intake,1,6) = 'Intact' and
animal_ins.sex_upon_intake != animal_outs.sex_upon_outcome
select product_code, sum(amount*price) as sales
from product join
(select product_id, sum(sales_amount) as amount
from offline_sale
group by product_id
) as amount_table on product.product_id = amount_table.product_id
group by product.product_id
order by sales desc, product.product_code asc