select p.member_name,
r.review_text,
r.review_date
from member_profile p
join rest_review r using(member_id)
where r.member_id = (select member_id from rest_review group by 1 order by count(*) desc limit 1)
order by 3,2
select sales_date,
product_id,
user_id,
sales_amount
from online_sale
where sales_date between '2022-03-01' and '2022-03-31'
union all
select sales_date,
product_id,
NULL as user_id,
sales_amount
from offline_sale
where sales_date between '2022-03-01' and '2022-03-31'
order by 1,2,3
select e1.id
from ecoli_data e1
join ecoli_data e2 on e1.parent_id = e2.id
join ecoli_data e3 on e2.parent_id = e3.id
where e3.parent_id is null
order by 1
with recursive cte (hour) as
(
select 0
union all
select hour + 1
from cte
where hour < 23
)
select cte.hour, count(animal_outs.animal_id) as 'count'
from cte
left join animal_outs
on cte.hour = hour(animal_outs.datetime)
group by cte.hour;
select distinct d.id,
d.email,
d.first_name,
d.last_name
from developers d
left join skillcodes s on s.code = d.skill_code & s.code
where s.category = 'Front End'
order by 1
select history_id,
case when datediff(end_date, start_date) + 1 >= 90
then floor(daily_fee * (1 - (
select discount_rate
from car_rental_company_discount_plan
where car_type = '트럭' and duration_type = '90일 이상'
) / 100) * (datediff(end_date, start_date) + 1))
when datediff(end_date, start_date) + 1 >= 30
then floor(daily_fee * (1 - (
select discount_rate
from car_rental_company_discount_plan
where car_type = '트럭' and duration_type = '30일 이상') / 100
) * (datediff(end_date, start_date) + 1))
when datediff(end_date, start_date) + 1 >= 7
then floor(daily_fee * (1 - (
select discount_rate
from car_rental_company_discount_plan
where car_type = '트럭' and duration_type = '7일 이상') / 100
)* (datediff(end_date, start_date) + 1))
else daily_fee * (datediff(end_date, start_date) + 1)
end as fee
from car_rental_company_rental_history h
join car_rental_company_car c using(car_id)
where c.car_type = '트럭'
order by 2 desc, 1 desc;
select c.car_id,
c.car_type,
round(c.daily_fee * 30 * (100-p.discount_rate)/100) as fee
from car_rental_company_car c
join car_rental_company_rental_history h on c.car_id = h.car_id
join car_rental_company_discount_plan p on c.car_type = p.car_type
where c.car_id not in (
select car_id
from car_rental_company_rental_history
where end_date >= '2022-11-01' and start_date <= '2022-12-01'
) and p.duration_type like '30%'
group by c.car_id
having c.car_type in ('세단', 'suv') and (fee >= 500000 and fee < 2000000)
order by 3 desc, 2, 1 desc;
select year(o.sales_date) as year,
month(o.sales_date) as month,
count(distinct o.user_id) as purchased_users,
round((count(distinct o.user_id) / (select count(*) from user_info where joined like '2021%')),1) as purchased_ratio
from user_info u
join online_sale o using (user_id)
where u.joined like '2021%'
group by 1,2
order by 1,2
select year(o.sales_date) as year,
month(o.sales_date) as month,
count(distinct o.user_id) as purchased_users,
round((count(distinct o.user_id) / count(distinct u.user_id)),2) as purchased_ratio
from user_info u
join online_sale o using (user_id)
where o.sales_date like '2021%'
and u.joined like '2021%'
group by 1,2;
=> 전체 가입자 대비가 아니라 해당 월 구매자 대비로 비율을 계산하게 되어서 정답이 될 수 없음.