Airbnb 한방 쿼리

김민준·2021년 12월 10일
0

라이징캠프 3주차

목록 보기
3/3
post-thumbnail

저번 시간에 만든 ERD를 바탕으로 Datagrip에서 한방 쿼리를 작성해 에어비앤비의 실제 화면들의 데이터들을 도출해 보았다.


프로필

select Users.user_name, user_profile.path, user_profile.introduction_text,
       user_profile.created_at, Reviews.review_id
from user_profile inner join Users
    on Users.user_id=101
           and user_profile.user_id = Users.user_id
    inner join Reviews
        on Reviews.user_id=Users.user_id;
  • 결과

유저의 이름, 보여줄 사진, 소개글, 회원가입일시, 유저가 남긴 리뷰들을 보여준다.


방 정보 화면

select Rooms.room_name, Users.user_name, Rooms.room_address, Rooms.room_latitude, Rooms.room_longitude,
       Rooms.room_price, Rooms.service_commission, Rooms.clean_up_cost,
       Rooms.room_description, Rooms.check_in_time, Rooms.check_out_time,
       Rooms.return_policy, Reviews.text
from Rooms, Reviews, Users
where Rooms.room_id=201
and Users.user_id=Rooms.host_id
and Reviews.room_id=Rooms.room_id;
  • 결과

    방 이름, 방 주소, 위도, 경도, 1박당 가격, 숙박세, 청소비, 방 설명, 체크인, 체크아웃 시간, 환불정책, 호스트아이디들을 보여준다.

검색화면

select Rooms.room_name, Rooms.room_wishes,  Rooms.room_average_rank,room_images.image_name,
       room_options.item1, room_options.item2, room_options.item3,
       room_amenities_id
from Rooms, room_images, room_options, room_amenities
where Rooms.location_id=905
and room_images.room_id=(select Rooms.room_id from Rooms where Rooms.location_id=905)
and room_options.room_option_id=(select Rooms.room_option_id
    from Rooms where Rooms.location_id=905)
and room_amenities.room_id=(select Rooms.room_id from Rooms where Rooms.location_id=905);
  • 결과

검색화면에 나오는 방 이름, 좋아요 여부, 평점, 이미지, 침실, 침대, 화장실 개수, 편의시설들을 보여준다.


위시리스트

select Wishelists.wishes_name, room_images.path
from Wishelists, room_images, wishes_middle
where Wishelists.user_id=101
and Wishelists.wishes_id=wishes_middle.wishes_id
and wishes_middle.room_id=room_images.room_id;
  • 결과

내가 만든 위시리스트의 이름과 이미지를 보여준다.


위시리스트 내부

select Wishelists.wishes_name, Rooms.room_name, Rooms.room_latitude, Rooms.room_longitude,
       room_images.image_name, Rooms.room_average_rank, room_options.item1,
       room_options.item2, room_options.item3
from Rooms, room_images, Wishelists, wishes_middle, room_options
where Wishelists.user_id=101
and Wishelists.wishes_id=wishes_middle.wishes_id
and Rooms.room_id=wishes_middle.room_id
and Rooms.room_id=room_images.room_id
and Rooms.room_option_id=room_options.room_option_id;
  • 결과

위시리스트의 이름, 좋아요한 방들, 방들의 위치, 사진들, 평점, 침실, 침대, 화장실의 개수를 보여준다.


유연한 검색

select property.property_name, Rooms.room_name, Rooms.room_price, room_images.path
from property, Rooms, room_images, property_middle_table
where property.property_id=3001
and property_middle_table.property_id=property.property_id
and Rooms.room_id=property_middle_table.room_id
and room_images.room_id=Rooms.room_id;
  • 결과

특성, 특성에 맞는 방들, 방의 가격, 사진들을 보여준다.

profile
기록하는 개발자가 되자

0개의 댓글