select cust_id, fname, credit_limit, gender
from custs
where credit_limit between 5000 and 9000
and (gender = 'F'
or gender is null);
조건결과
2. 고객 테이블(custs)와 주문 테이블(orders)을 이용하여 다음 조건의 결과를 검색하세요
select lname, order_id, order_date, phone, order_total
from custs, orders
where custs.cust_id = orders.cust_id
and order_mode = 'online';
조건결과
3. 주문 테이블(orders)을 활용하여 아래의 조건에 맞는 결과를 검색하세요
select sales_rep_id, cust_id, order_total
from orders
where order_mode not in ('online')
and order_total < (select avg(order_total)
from orders
where order_mode = 'direct')
order by order_total desc;
조건결과
4. 상품 테이블(prods), 주문 테이블(orders), 주문 상세 테이블(order_items), 고객 테이블(custs)을 사용하여 상품을 구매했다가 취소한 고객의 번호와 이름, 상품번호, 주문일자, 주문했던 수량, 주문 단가 및 금액을 검색하세요
select c.cust_id, c.lname, p.prod_id, p.prod_name
, o.order_date, oi.quantity, oi.unit_price
, (oi.quantity * oi.unit_price) amt
from prods p, orders o, order_items oi, custs c
where c.cust_id = o.cust_id
and o.order_id = oi.order_id
and oi.prod_id = p.prod_id
and exists (select *
from order_cancel
where order_id = oi.order_id
and prod_id = oi.prod_id)
order by c.cust_id, o.order_date, p.prod_id;
조건결과
5. 상품 테이블(prods)과 주문 상세 테이블(order_items), 주문 테이블(orders), 고객 테이블(custs)을 이용하여 미국에서 거주하는 고객이 주문한 상품의 번호와 이름, 주문 수량, 주문 단가, 주문 금액을 조회하세요
select o.order_id, p.prod_id, p.prod_name
, oi.quantity, oi.unit_price
, (oi.quantity * oi.unit_price) amt
from prods p, orders o, order_items oi, custs c
where c.cust_id = o.cust_id
and o.order_id = oi.order_id
and oi.prod_id = p.prod_id
and c.cust_id in (select cust_id
from custs
where country = 'USA')
order by amt desc;