Sql Apache Drill上的union中为NULL
我有一个查询,需要使用Union来获取一行中的所有日期。Union中不支持NULL。请注意,这是一个示例查询Sql Apache Drill上的union中为NULL,sql,null,apache-drill,mapr,Sql,Null,Apache Drill,Mapr,我有一个查询,需要使用Union来获取一行中的所有日期。Union中不支持NULL。请注意,这是一个示例查询 Select ID, Supplydate as A_SupplyDate,OrderDate as A_Orderdate, NULL as B_SupplyDate,NULL as B_OrderDate from tbl where Category='A' union Select ID, NULL
Select ID, Supplydate as A_SupplyDate,OrderDate as A_Orderdate,
NULL as B_SupplyDate,NULL as B_OrderDate
from tbl where Category='A'
union
Select ID, NULL as A_SupplyDate,NULL as A_Orderdate,
Supplydate as B_SupplyDate,OrderDate as B_OrderDate
from tbl where Category='B'
将null强制转换为适当的数据类型,例如
Cast(null作为bigint)
如果null不起作用,为什么不尝试“”呢?我想显示null,不确定IFNULL在这种情况下是否有效我明白了-你现在得到的错误到底是什么?非法使用null你在没有联合的常规查询中也会得到同样的错误吗?好的,那么就把它放空白,然后再加上null如果空白-我会在上面调整代码只要替换nullif(1,1)
就足够让它运行了。看起来有点傻。
select id, nullif(a_supplydate,'')a_supplydate, a_orderdate, nullif(b_supplydate,'')b_supplydate, b_orderdate from
(Select ID, Supplydate as A_SupplyDate,OrderDate as A_Orderdate,
'' as B_SupplyDate,NULL as B_OrderDate
from tbl where Category='A'
union
Select ID, '' as A_SupplyDate,NULL as A_Orderdate,
Supplydate as B_SupplyDate,OrderDate as B_OrderDate
from tbl where Category='B')A