Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图摆脱 SQL 中的重复组,但问题是它们并不是真正的重复组。
我有一张这样的桌子:
a | b 0 | 1 2 | 3
但是,该表还添加了 B、A,因此我最终将其作为决赛桌:
a | b 0 | 1 2 | 3 -------- 1 | 0 3 | 2
我想要做的是返回不同的对(第一个表),我遇到了问题。任何提示将不胜感激!
试试这个:
select distinct (case when a < b then a else b end) as First, (case when a < b then b else a end) as Second from t
如果您使用的是 Oracle(这是 SQLPlus 的假设),您可以将其简化为:
select distinct least(a, b), greatest(a, b) from t