728x90
코드카타
SELECT ri.rest_id,
ri.rest_name,
ri.food_type,
ri.favorites,
ri.address,
ROUND(AVG(review_score),2) AS SCORE
FROM REST_INFO ri JOIN REST_REVIEW rr ON ri.rest_id =rr.rest_id
WHERE address LIKE '서울%'
GROUP BY ri.rest_id
ORDER BY score desc, favorites desc;
SELECT history_id, car_id,
DATE_FORMAT(start_date,'%Y-%m-%d') START_DATE,
DATE_FORMAT(end_date,'%Y-%m-%d') END_DATE,
CASE WHEN DATEDIFF(end_date, start_date) >= 29 THEN '장기 대여'
ELSE '단기 대여' END AS RENT_TYPE
-- 빌린 당일에 대여한 사람은 DATEDIFF(end_date, start_date)의 값이 0이 되어버리기 때문에 30일 이상인 사람이지만, 0부터 세어서 29 이상인 값을 찾아야함
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
WHERE DATE_FORMAT(start_date,'%Y-%m') = '2022-09'
ORDER BY history_id desc;
SELECT car_id,
ROUND(AVG(DATEDIFF(end_date, start_date)+1),1) AVERAGE_DURATION
FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY
GROUP BY car_id
HAVING AVERAGE_DURATION >= 7
ORDER BY 2 desc, car_id desc;
SELECT ID, NAME, HOST_ID
FROM (
SELECT ID, NAME, HOST_ID,
COUNT(HOST_ID) OVER (PARTITION BY HOST_ID) AS count
FROM PLACES
GROUP BY ID
ORDER BY host_id ) AS sub
WHERE count >= 2
ORDER BY ID;
SELECT CART_ID
FROM CART_PRODUCTS
WHERE NAME = 'Milk'
AND CART_ID in
(
SELECT CART_ID
FROM CART_PRODUCTS
WHERE NAME = 'Yogurt'
)
ORDER BY 1;
https://dydatablog.tistory.com/57
728x90
'내일배움캠프 > TIL' 카테고리의 다른 글
[TIL]241212_SQL코드카타, Python 개인과제 문제1~3 (2) | 2024.12.12 |
---|---|
[TIL]241211_코트카타Lv.4 (복습 필요), 파이썬 3주차 복습 (1) | 2024.12.11 |
[TIL]2412209_코드카타, 파이선 종합반 강의 (2) | 2024.12.09 |
[WIL]내일배움캠프_2주차 (1) | 2024.12.08 |
[TIL]코드카타 (1) | 2024.12.06 |