Remove duplicate passenger train shifts, value interchange of two fields as duplicate values

Source: Internet
Author: User

Take out the recurring passenger train frequency

SELECT CID, From_city, to_city, Ticket_price
From city
WHERE CID in (SELECT DISTINCT first_value (CCID) through (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, To_city VARCHAR2 (), ticket_price number)

INSERT into city (Cid,from_city,to_city,ticket_price)

SELECT,' Beijing ',' Shanghai ', from dual

UNION All

SELECT 02, ' Shanghai ', ' Shenzhen ', 280 from dual

UNION All

SELECT 03, ' Wuhan ', ' Guangzhou ', from dual

UNION All

SELECT 04, ' Xian ', ' Chengdu ', from dual

UNION All

SELECT 05, ' Shenzhen ', ' Shenzhen ', from dual

UNION All

SELECT,' Shanghai ',' Beijing ', from dual

UNION All

SELECT 07, ' Guangzhou ', ' Wuhan ', from dual

UNION All

SELECT 08, ' Shenzhen ', ' Shanghai ', 280 from dual

UNION All

SELECT 09, ' Chengdu ', ' Chongqing ', from dual

COMMIT;

Remove duplicate passenger train shifts, value interchange of two fields as duplicate values

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.