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.
我想选择 a+b 列的任何不同组合并选择 c 列
sql基本上是这样的:
SELECT DISTINCT (a, b), c FROM mytable
返回错误:操作数应包含 1 列
这甚至可能吗?
您想group by改用:
group by
SELECT a, b, c FROM mytable group by a, b;
Distinct适用于所有列,而不仅仅是少数。c此公式从其中一行返回任意值。更典型的是,您会选择一个值,例如:
Distinct
c
SELECT a, b, min(c) FROM mytable group by a, b;