码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-04-25 00:06:41      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

取出重复的客运车班次

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;

 

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

标签:

原文地址:http://www.cnblogs.com/wwxbi/p/4455065.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!