我想将date,hits.hour和hits.minute字段组合为一个日期字段,Tableau可以轻松地对其进行可视化读取。

目前,日期是一个字符串,而hits.hour和hits.minute是整数。

最后,日期应类似于YYYY-MM-DD和hh:mm。

Atm我将日期转换为字符串,但是我现在不知道如何组合字段,或者通常来说如果第一步正确的话。

最好,
帕斯卡

SELECT
fullVisitorId,
visitId,
date,
CAST (hits.hour as string) AS hour,
CAST (hits.minute as string) AS minute,
totals.transactions ,
hits.item.productName,
FROM [X.ga_sessions_20180221]
WHERE hits.hitNumber =1
GROUP BY
  fullVisitorId, visitId, date, hour, minute, hits.item.productName, totals.transactions

最佳答案

您只需要串联选定的值

SELECT
    fullVisitorId,
    visitId,
    CAST(date as string) +' & ' + CAST (hits.hour as string) + ':' + CAST (hits.minute as string) AS datetime,
    totals.transactions ,
    hits.item.productName,
FROM [X.ga_sessions_20180221]
WHERE
    hits.hitNumber =1
GROUP BY
  fullVisitorId, visitId, date, hour, minute, hits.item.productName, totals.transactions

关于sql - 合并日期,hits.hour和hits.minute字段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48944327/

10-11 02:49