【问题标题】:Getting unique tuples in SQL [duplicate]在 SQL 中获取唯一元组 [重复]
【发布时间】:2016-03-06 13:42:59
【问题描述】:

我有一张像下面这样的表格,我想获得唯一值。

from_st     to_st       fare
---------------------------
Bangalore   Hyderabad   600
Hyderabad   Bangalore   600
Bangalore   chennai     500
chennai     Bangalore   500
Bangalore   noida       1500
noida       Banagalore  1500
bangalore   delhi       3000
bangalore   pune        2000

我需要像班加罗尔到海得拉巴和海得拉巴到班加罗尔这样的数据是重复的。所以我只想要其中一条记录。

想要的输出:

from_st     to_st       fare
---------------------------
Bangalore   Hyderabad   600
Bangalore   chennai     500
Bangalore   noida       1500
bangalore   delhi       3000
bangalore   pune        2000

【问题讨论】:

标签: sql oracle


【解决方案1】:

你可以这样做:

 select distinct least(from_st, to_st), greatest(from_st, to_st), fare
 from your table;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 2012-06-30
    • 2013-09-09
    相关资源
    最近更新 更多