Programing/데이터베이스(MySQL)

[프로그래머스] MySQL Lv.1 (정답률 85% 이하)

hye3193 2023. 10. 31. 17:14

조건에 부합하는 중고거래 댓글 조회하기

SELECT board.title, board.board_id,
    reply.reply_id, reply.writer_id,
    reply.contents,
    date_format(reply.created_date, '%Y-%m-%d')
        as created_date
from used_goods_board as board
    inner join used_goods_reply as reply
    on board.board_id = reply.board_id
where board.created_date like '2022-10%'
order by reply.created_date, board.title

 

자동차 대여 기록에서 장기/단기 대여 구분하기

select history_id,
    car_id,
    date_format(start_date, '%Y-%m-%d') as start_date,
    date_format(end_date, '%Y-%m-%d') as end_date,
    case
    when datediff(end_date, start_date) >= 29
    then '장기 대여'
    else '단기 대여'
    end as rent_type
from CAR_RENTAL_COMPANY_RENTAL_HISTORY
where start_date like '2022-09%'
order by history_id desc

 

특정 옵션이 포함된 자동차 리스트 구하기

SELECT *
from car_rental_company_car
where options like '%네비게이션%'
order by car_id desc

 

최댓값 구하기

SELECT max(datetime)
from animal_ins

 

과일로 만든 아이스크림 고르기

SELECT first_half.flavor
from first_half inner join icecream_info
    on first_half.flavor = icecream_info.flavor
where first_half.total_order > 3000
    and icecream_info.ingredient_type = 'fruit_based'
order by first_half.total_order desc


모든 레코드 조회하기

SELECT *
from ANIMAL_INS
order by animal_id


평균 일일 대여 요금 구하기

SELECT round(avg(daily_fee), 0) as average_fee
from CAR_RENTAL_COMPANY_CAR
where car_type = 'SUV'


조건에 맞는 도서 리스트 출력하기

SELECT book_id,
    date_format(published_date, '%Y-%m-%d') as published_date
from book
where published_date like '2021-%'
    and category = '인문'
order by published_date