取出重复的客运车班次,两个字段的值互换视为重复值

取出重复的客运车班次

SELECT CID, FROM_CITY, TO_CITY, TICKET_PRICE
  FROM CITY
 WHERE CID IN (SELECT DISTINCT FIRST_VALUE(CCID) OVER(PARTITION BY FROM_CITY, TO_CITY ORDER BY FROM_CITY, TO_CITY)
                 FROM (SELECT A.CID          CCID,
                              A.FROM_CITY    FROM_CITY,
                              A.TO_CITY      TO_CITY,
                              A.TICKET_PRICE PRICE
                         FROM CITY A
                       UNION ALL
                       SELECT B.CID          CCID,
                              B.TO_CITY      FROM_CITY,
                              B.FROM_CITY    TO_CITY,
                              B.TICKET_PRICE PRICE
                         FROM CITY B
                        ORDER BY FROM_CITY, TO_CITY))

 

 

CREATE TABLE CITY (CID NUMBER,FROM_CITY VARCHAR2(50),TO_CITY VARCHAR2(50),ticket_price NUMBER)

INSERT INTO city (CID,FROM_CITY,TO_CITY,ticket_price)

SELECT 01,'北京','上海',300 FROM dual

UNION ALL

SELECT 02,'上海','深圳',280 FROM dual

UNION ALL

SELECT 03,'武汉','广州',120 FROM dual

UNION ALL

SELECT 04,'西安','成都',60 FROM dual

UNION ALL

SELECT 05,'深圳','深圳',30 FROM dual

UNION ALL

SELECT 06,'上海','北京',300 FROM dual

UNION ALL

SELECT 07,'广州','武汉',120 FROM dual

UNION ALL

SELECT 08,'深圳','上海',280 FROM dual

UNION ALL

SELECT 09,'成都','重庆',60 FROM dual

COMMIT;

 

posted @ 2015-04-24 23:47  智能先行者  阅读(408)  评论(0编辑  收藏  举报