https://solvesql.com/problems/sales-summary/
이 레스토랑의 요일별 매출액의 평균을 계산하는 문제입니다.
with AA AS(SELECT sum(total_bill) AS total, day FROM tips GROUP BY day)
SELECT round(avg(total),2)
FROM AA
https://solvesql.com/problems/inspection-needed-bike/
1달에 주행 거리가 50km 이상인 자전거의 아이디를 불러오는 문제입니다.
SELECT bike_id
FROM rental_history
WHERE date_format(rent_at,"%y-%m") = '21-01'
GROUP BY bike_id
having sum(distance) >= 50000
with절을 이용한 풀이
with AA AS (SELECT sum(distance) distance ,bike_id
FROM rental_history
WHERE date_format(rent_at,"%y-%m") = '21-01'
GROUP BY bike_id )
SELECT bike_id
FROM AA
WHERE distance >= 50000
https://solvesql.com/problems/installment-month/
SELECT
payment_installments,
count(distinct (order_id)) order_count,
MIN(payment_value) min_value,
MAX(payment_value) max_value,
AVG(payment_value) avg_value
FROM
olist_order_payments_dataset
WHERE
payment_type = 'credit_card'
GROUP BY
payment_installments