我想在Null值的ScanDate列的值中插入timestamp列。
我需要在Tableau中使用它,如果我将值分隔开,则会得到错误的结果
select distinct A.RootDocId, A.LastEventAppId, A.LastEventStatus,
case when B.Value = '' then A.Timestamp else
PARSE_TIMESTAMP('%d/%m/%Y %H:%M:%S',
replace(regexp_replace(B.Value, '[/-]1([7-9]) ', '/201\\1 '), '-', '/'))
end ScanDate, C.Value Federation, A.timestamp
from `moonoia-bpo-run.dam.documentroot` A
left join unnest(Metadata) B ON B.Key like 'ScanDate'
left join unnest(Metadata) C ON C.Key like '%ederation'
limit 100
我期望如此:
扫描日期为null
时,应将其替换为timestamp
。
答案 0 :(得分:2)
尝试一下:
select RoodDocId,
LastEventAppId,
LastEventStatus,
coalesce(ScanDate, timestamp),
Federation,
timestamp
from (
-- here your whole query that you have
) a
答案 1 :(得分:1)
Scandate为null的地方,将其替换为时间戳记
您应该使用COALESCE函数
为COALESCE(Scandate, timestamp)
或者您可以如下所示“修复”查询(B.Value = ''
-> IFNULL(B.Value, '') = ''
)
select distinct A.RootDocId, A.LastEventAppId, A.LastEventStatus,
case when IFNULL(B.Value, '') = '' then A.Timestamp else
PARSE_TIMESTAMP('%d/%m/%Y %H:%M:%S',
replace(regexp_replace(B.Value, '[/-]1([7-9]) ', '/201\\1 '), '-', '/'))
end ScanDate, C.Value Federation, A.timestamp
from `moonoia-bpo-run.dam.documentroot` A
left join unnest(Metadata) B ON B.Key like 'ScanDate'
left join unnest(Metadata) C ON C.Key like '%ederation'
limit 100
答案 2 :(得分:1)
使用Tableau对Tableau数据源中的关系(联接)建模时,通常会更好,让该工具为您的特定可视化生成优化的SQL。如果您亲自编写自己的SQL,Tableau当然会尊重它,但不会尝试对其进行优化。
Tableau中提供了您在主流SQL中几乎可以做的所有事情,而如果您决定探索该路线,则无需借助手写SQL。 SQL的Coalesce()的Tableau计算等效项称为IF_NULL()。