如何删除重复项(不明确)

时间:2018-01-27 20:22:47

标签: sql postgresql

我想从路线中选择机场,事情是机场对显示2次:

results

我想只显示一半(例如只有BZK DME而不是BZK DME和DME BZK)

SELECT 
   departure_airport, 
   arrival_airport, 
   departure_city, 
   arrival_city, 
   count (departure_airport) as sum
FROM 
    routes
GROUP BY
    departure_airport, 
    arrival_airport, 
    departure_city, 
    arrival_city
HAVING  
    count (departure_airport) > 2;

2 个答案:

答案 0 :(得分:1)

只需使用[ { id: 'abc' }, { id: 'ghi' }, { id: 'def' } ]

<

这假设所有路线都有精确对。这是你的问题所暗示的。

答案 1 :(得分:0)

您可以使用Row_Number()选择到达机场和出发机场的特定组合

(select departure_airport, arrival_airport, departure_city, arrival_city, 
count (departure_airport) as sum,row_number()(order by departure_airport,arrival_airport) as row
from routes
group by departure_airport, arrival_airport, departure_city, arrival_city
having count (departure_airport) > 2
 )where row=1