admin

合并日期,hits.hour和hits.minute字段

sql

我想将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

阅读 182

收藏
2021-07-01

共1个答案

admin

您只需要串联选定的值

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
2021-07-01