在 scandate 列中插入时间戳列?
Insert the timestamp column in the scandate column?
我想在具有 Null 值的 ScanDate 列的值中插入时间戳列。
我需要在 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 `serv.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
我预料到了:
Scandate 是 null
,应该用 timestamp
代替。
Where Scandate is null, to be replaced with the timestamp
你应该使用 COALESCE 函数
作为COALESCE(Scandate, timestamp)
或者您可以 "fix" 您的查询 (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 `serv.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
试试这个:
select RoodDocId,
LastEventAppId,
LastEventStatus,
coalesce(ScanDate, timestamp),
Federation,
timestamp
from (
-- here your whole query that you have
) a
使用 Tableau 在 Tableau 数据源中对关系(连接)进行建模并让该工具为您的特定可视化生成优化的 SQL 通常会更好。如果您自己手写 SQL,Tableau 当然会尊重它,但不会尝试对其进行优化。
几乎所有您在主流 SQL 中会做的事情都可以在 Tableau 中使用,而无需借助手写 SQL 如果您决定探索那条路线。 SQL 的 Coalesce() 的 Tableau 计算等效项称为 IF_NULL()。
我想在具有 Null 值的 ScanDate 列的值中插入时间戳列。
我需要在 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 `serv.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
我预料到了:
Scandate 是 null
,应该用 timestamp
代替。
Where Scandate is null, to be replaced with the timestamp
你应该使用 COALESCE 函数
作为COALESCE(Scandate, timestamp)
或者您可以 "fix" 您的查询 (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 `serv.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
试试这个:
select RoodDocId,
LastEventAppId,
LastEventStatus,
coalesce(ScanDate, timestamp),
Federation,
timestamp
from (
-- here your whole query that you have
) a
使用 Tableau 在 Tableau 数据源中对关系(连接)进行建模并让该工具为您的特定可视化生成优化的 SQL 通常会更好。如果您自己手写 SQL,Tableau 当然会尊重它,但不会尝试对其进行优化。
几乎所有您在主流 SQL 中会做的事情都可以在 Tableau 中使用,而无需借助手写 SQL 如果您决定探索那条路线。 SQL 的 Coalesce() 的 Tableau 计算等效项称为 IF_NULL()。