qq_29357869 2018-04-16 06:36 采纳率: 50%
浏览 2300
已采纳

SQL去重问题(应该是比较高级的去重?)

原题:
List the names of all the pairs of U.S. counties that touch each other only in a point (or multiple points, but not lines). Make sure to list each pair only once, and sort results alphabetically by the name of the first county in a pair and then by the name of the second county.

问题:
如何保证每一对只显示一次?(make sure to list each pair only once)。

举例:
返回的记录是:
1 A B
2 A C
3 A D
4 B A

我们视 1 和 4 是重复的, 如何去除

  • 写回答

9条回答

  • 咱姐夫 2018-04-16 07:43
    关注

    SELECT (CASE WHEN 第一列<第二列 THEN 第一列+第二列 ELSE 第二列+第一列 END) as AB from table group by AB

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?