【发布时间】:2021-02-18 23:39:29
【问题描述】:
我有两个表使用联合来组合它们的结果集我的问题是 UNION 中的每个 SELECT 语句必须具有相同数量的列和数据类型,我没有相同数量的列所以正在创建空列
select
d.deal_id as order_id,
EXISTS(select * from table1 c where d.user_id = c.user_id) as IsUser, --this returns boolean value
from table 1 c
union
select
cast(o.id as varchar) as order_id,
coalesce('No_user'::text,'0'::text) as IsUser, --i get an error :UNION types boolean and character varying cannot be matched
from table2 o
如何在 table2 中创建一个与 table1 的布尔数据类型匹配的空列
【问题讨论】:
-
你能提供表格内容和你的设计者输出吗?
标签: postgresql union exists sqldatatypes