← 목록

데이터베이스와 SQL 문법 기초반 수료시험(3)

Lv.4 SQL
문제 설명
문제
쇼핑몰 데이터가 `customers_sp`(고객), `orders_sp`(주문), `order_items`(주문상세), `products_sp`(상품) 4개 테이블로 나뉘어 저장되어 있습니다.
네 테이블을 조인하여 한 장의 주문 내역서를 만드는 SQL을 작성하세요.

출력 컬럼
order_idorder_tscustomer_nameproduct_namecategoryquantityunit_priceamount

컬럼설명
order_id주문번호
order_ts주문일
customer_name고객명
product_name상품명
category카테고리
quantity수량
unit_price단가
amount금액 = 수량 × 단가

조건
- 네 테이블은 각각의 기본키-외래키 관계(`customer_id`, `order_id`, `product_id`)로 연결합니다.
- 주문된 상품만 출력합니다.
- `amount`는 `quantity * unit_price`로 계산합니다.
- 결과는 주문일(order_ts) 오름차순, 같은 날이면 금액(amount) 내림차순으로 출력하세요.
솔루션 SQL
실행 결과
실행 또는 제출하면 결과가 여기에 표시됩니다.