select *
from tips
where total_bill> (select avg(total_bill)
from tips)
-- 1번째
select round(sum(total_bill)/4,2) avg_sales
from tips
-- 2번째
select round(sum(total_bill)/count(DISTINCT(day)),2) avg_sales
from tips
select DISTINCT(day) day_of_week
from tips
2️⃣ 난이도 2 _문제 해결
2-1. 두 테이블 결합하기
select DISTINCT(r.athlete_id)
from (select id
from events
where sport = "Golf") as e inner join records r
on r.event_id = e.id
2-2. 레스토랑 웨이터의 팁 분석
select day, time, round(avg(tip),2) avg_tip, round(avg(size),2) avg_size
from tips
group by day, time
order by day, time
2-3. 일별 블로그 방문자 수 집계
select event_date_kst as dt, count(DISTINCT(user_pseudo_id)) as users
from ga
where event_date_kst>= '2021-08-02' and event_date_kst<='2021-08-09'
group by event_date_kst
2-4. 우리 플랫폼에 정착한 판매자 2
select seller_id, count(distinct(order_id)) as orders
from olist_order_items_dataset
where price>=50
group by seller_id
having count(distinct(order_id))>=100
order by orders desc
2-5. 레스토랑의 일일 매출
select day, sum(total_bill) revenue_daily
from tips
group by day
having sum(total_bill) >= 1000
order by revenue_daily desc