【发布时间】:2023-01-28 19:48:03
【问题描述】:
我有一个名为 test_table 的表,如下所示
| Column | Type | Collation | Nullable | Default |
|---|---|---|---|---|
| ts | timestamp with time zone | not null | ||
| ba | integer | |||
| ca | integer |
现在,如果我在 ba 列上运行 distinct,我得到
| ba |
|---|
| 5 |
| 10 |
| 11 |
同样,如果我在 ca 列上运行 distinct,我会得到
| ca |
|---|
| 5 |
| 10 |
| 18 |
| 20 |
现在我想合并这两个 distinct 列的值,并从 combined 值中得到一个 distinct,这样输出如下所示
预期产出
| combo |
|---|
| 5 |
| 10 |
| 11 |
| 18 |
| 20 |
我可以像这样在多列上做一个DISTINCT
select distinct ba, ca from test_table;
但我无法弄清楚如何将这两列组合起来并从中获得不同的值。
【问题讨论】:
标签: sql postgresql union distinct