合并命令问题

g9icjywg  于 2021-06-29  发布在  Hive
关注(0)|答案(1)|浏览(433)

我正在尝试使用coalesce函数运行配置单元查询来创建视图。但它正在引发错误,如无法识别表达式规范中“(”select“realvalue”)附近的输入
查询如下。请帮助并说明这里面有什么问题。

CREATE VIEW IF NOT EXISTS exampledb.`ara_service` AS
SELECT T1.EntityId, T1.entityname AS EntityName,
       T1.`xxx`,
       T1.`yyy`,
       COALESCE (T1.`aaa`, (SELECT `realvalue` FROM exampledb.`aba_service`
                            WHERE `id` = '333')) AS `CombinedValue`,
       T1.`ddd`,
       T1.`jjj`,

等。。
请帮忙。错误是在coalesce中使用select语句。NoviableException(231@[435:1:precedenceequalexpression:((lparen precedencebitwiseorexpression逗号)=>PrecedenceEqualExpressionMultiple | precedenceequalexpressionsingle);])
谢谢

nkcskrwz

nkcskrwz1#

如果您只需要一个默认值,您可以这样做

CREATE VIEW IF NOT EXISTS exampledb.`ara_service` AS
SELECT T1.EntityId, T1.entityname AS EntityName,
       T1.`xxx`,
       T1.`yyy`,
       COALESCE (T1.`aaa`, def.`realvalue` ) AS `CombinedValue`,
       T1.`ddd`,
       T1.`jjj`,
FROM your_table T1
CROSS JOIN (
    SELECT `realvalue` 
    FROM exampledb.`aba_service` WHERE `id` = '333') def

相关问题