Create table seat
(
seat_num Integer NOT NULL,
seat_grade Char(10) NULL,
price_code Char(20) NOT NULL,
Primary Key (seat_num)
);
Create table price
(
seat_vip Integer NULL,
seat_R Integer NULL,
seat_S Integer NULL,
seat_A Integer NULL,
seat_B Integer NULL,
price_code Char(20) NOT NULL,
Primary Key (price_code)
);
Alter table seat add foreign key(price_code) references price (price_code) on update no action on delete no action;
Insert into price(seat_vip, seat_R, seat_S, seat_A, seat_B, price_code) values (100000,80000,60000,40000,20000,'p001');
Insert into seat(seat_num, seat_grade, price_code) values ('3','seat_VIP','p001');
위의 방식대로 테이블을 생성 하면 seat테이블에는 좌석 번호와 좌석 등급, 등급 코드(외래키) 가 들어가게 되고
price테이블에는 각 등급별 가격이 등급 코드와 함께 입력이 됩니다.
seat 테이블
─────┬─────┬──────┐
seat_num │seat_grade│ price_code │
──────────────────┤
3 seat_VIP p001 │
──────────────────┤
price테이블
─────┬─────┬─────┬─────┬─────┬─────┬
seat_vip │ seat_R │ seat_S │ seat_A │ seat_B │price_code│
───────────────────────────────────┤
100000 80000 60000 40000 20000 p001 │
───────────────────────────────────┤
SELECT문을 이용해서 seat테이블의 3번 테이블을 선택하면 3번 테이블이 VIP석이기 때문에 price테이블의 100000원을 출력하게 할순 없을까요???
///////////////////////////////////////////////////////////////////////////////////
select seat_vip
from price, seat
where price.price_code = seat.price_code
and seat.seat_num ='3';
////////////////////////////////////////////////////////////////
위의 코드를 실행하면 seat_vip값인 100000이 출력되는데
그런 방식이 아닌 seat.price_code에 들어있는 값을 찾아 price테이블의 투플로 인식하게 할수 있습니까??
////////////////////////////////////////////////////////////////////
select price.(values(seat.seat_grade))
from price, seat
where price.price_code = seat.price_code
and seat.seat_num ='3';
/////////////////////////////////////////////////////////////////
혹시 이게 될까 싶어 해봤는데 안돼더군요... 이게 실행되기 위해 코드를 어케 바꾸면 좋을까요..
좋은 답변 부탁드립니다. |