1

我已经创建了一个表 TRKTRIPLEG(如下):

CREATE TABLE TRKTRIPLEG(
        T#              NUMBER(10)      NOT NULL,
        LEG#            NUMBER(2)       NOT NULL,
        DEPARTURE       VARCHAR(30)     NOT NULL,
        DESTINATION     VARCHAR(30)     NOT NULL,
        CONSTRAINT TRKTRIPLEG_PKEY PRIMARY KEY (T#, LEG#),
        CONSTRAINT TRKTRIPLEG_UNIQUE UNIQUE(T#, DEPARTURE, DESTINATION),
        CONSTRAINT TRKTRIPLEG_FKEY1 FOREIGN KEY (T#) REFERENCES TRKTRIP(T#) );

我在表中插入了一些值:

INSERT INTO TRIPLEG VALUES(10, 1, 'Perth', 'Sydney');
INSERT INTO TRIPLEG VALUES(10, 2, 'Sydney', 'Brisbane');

我想出来的输出应该是这样的:

T# ORIGIN DESTINATION1 DESTINATION2
---- ---------- ------------------- ----------------
10 Perth   Sydney       Brisbane

我已经坚持了很长一段时间,似乎无法做到这一点......对此有任何帮助吗?

4

1 回答 1

0
select o.t#, 
       o.departure,
       o.destination as destination_1,
       d.destination as destionation_2
from tripleg o
  join tripleg d on o.t# = d.t# and o.departure = d.origin
于 2012-11-17T08:51:20.660 回答