0

假设我的桌子上有这些。

Index   Resultant   First   Second
1       Ice         Water       Cold
2       Cold Air    Water       Cold
3       Cold Wind   Water       Cold
4       Hot Air     Volcano     Air
5       Normal Air  Oxygen      Hydrogen
6       Ice         Cold        Water
7       Cold Air    Cold        Water
8       Cold Wind   Cold        Water

我只想显示这些

Index   Resultant   First   Second
1       Ice         Water       Cold
2       Cold Air    Water       Cold
3       Cold Wind   Water       Cold
4       Hot Air     Volcano     Air
5       Normal Air  Oxygen      Hydrogen

因为如果你翻转它们,底部的 3 个区域都会重复。但我不希望第 1,2 行也被隐藏,因为它也是水和冷的组合。

4

1 回答 1

6
select least(col1, col2), greatest(col1, col2)
from MyTable
group by least(col1, col2), greatest(col1, col2)

SQL 小提琴示例

于 2012-10-01T14:34:00.360 回答