简体   繁体   English

presto:如何将 2 列的值合并为一列

[英]presto: how to combine 2 columns' values into one column

I am a beginner of SQL.我是 SQL 的初学者。 I have a table like the following:我有一个如下表:

Id start_place  end_place
1   a            b
2   b            c 
3   d            e
4   a            e

desired output:所需的 output:

 place
 a
 b
 c
 d
 e

I want to find combine the distinct values and distinct values from start_place and end_place and combine them into a column (if there are duplicates, eg, b are in both start and end place, show b only once).我想从 start_place 和 end_place 中找到组合不同的值和不同的值,并将它们组合成一列(如果有重复项,例如,b 在开始和结束位置,只显示一次)。

You can use union :您可以使用union

select start_place
from t
union   -- on purpose to remove duplicates
select end_place
from t;

Note that union removes duplicates.请注意, union删除重复项。 Under most circumstances, you want union all so you don't incur the overhead of removing duplicates.在大多数情况下,您希望union all ,这样您就不会产生删除重复项的开销。 In this case, though, duplicate remove is what you really want.但是,在这种情况下,重复删除是您真正想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM