Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何建立;“虚拟列”;为了联盟?_Sql - Fatal编程技术网

Sql 如何建立;“虚拟列”;为了联盟?

Sql 如何建立;“虚拟列”;为了联盟?,sql,Sql,根据我的理解,“UNION中的每个SELECT语句必须具有相同的列数。这些列还必须具有相似的数据类型。此外,每个SELECT语句中的列必须具有相同的顺序。”如果第一个SELECT语句的列数超过第二个SELECT语句可以生成的列数,该怎么办。我的意思是:让我们说我想 SELECT "City", "Country", "Continent" from table1 UNION SELECT "City", "Country" from table2 …假设表2不包含名为“Con

根据我的理解,“UNION中的每个SELECT语句必须具有相同的列数。这些列还必须具有相似的数据类型。此外,每个SELECT语句中的列必须具有相同的顺序。”如果第一个SELECT语句的列数超过第二个SELECT语句可以生成的列数,该怎么办。我的意思是:让我们说我想

SELECT "City", "Country", "Continent" from table1  
UNION  
SELECT "City", "Country" from table2     
…假设表2不包含名为“Continental”的列,但出于我的需要,表2中的记录在该列中可以为空或NULL。我正在使用dashDB。

您始终可以添加“虚拟”列:



您好,
您可以使用

 SELECT "City", "Country", "Continent" from table1  
UNION  
SELECT "City", "Country", ' ' as "Continent"  from table2


它认为“大陆”在表2中为空

是的,先生!这就是我要找的!谢谢你@Tim Schmelter不幸的是,这是无法被含蓄地理解的
 SELECT "City", "Country", "Continent" from table1  
UNION  
SELECT "City", "Country", ' ' as "Continent"  from table2
 SELECT "City", "Country", "Continent" from table1  
    UNION  
    SELECT 

"City", "Country", NULL as "Continent"  from table2