![](/img/trans.png)
[英]Union tables in Vertica SQL where tables have different order of columns?
[英]Union all in Vertica SQL based on tables with different number of columns?
你好,我在 Vertica SQL 中有兩個表:
表格1
col1 col2 col3
1 3 5
2 4 6
表 2
col1 col2
11 33
22 44
我想 UNION 這兩個表,因此我想擁有:
col1 col2 col3
1 3 5
2 4 6
11 33 NULL
22 44 NULL
我怎樣才能在vertica中做到這一點
使用null
如下:
select col1, col2, col3 from table1
union
select col1, col2, null from table2
通常,您應該使用UNION ALL
並使用您想要的任何默認值定義額外的列:
select col1, col2, col3
from table1
union all
select col1, col2, NULL as col3
from table2;
UNION
會產生刪除重復項的開銷。 通常,除非您打算刪除重復項,否則您應該使用UNION ALL
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.