Combine date, hits.hour & hits.minute field

心已入冬 提交于 2019-12-24 10:32:28

问题


I would like to combine the date, hits.hour & hits.minute field into one date-field that can easily be read by Tableau for visualization.

At the moment the date is a string and the hits.hour & hits.minute are integers.

In the end the date should be something like YYYY-MM-DD & hh:mm.

Atm I converted the date to a string but I dont know how to combine the fields now, or in general if this first step was correct.

Best, Pascal

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

回答1:


You just need to concatenate selected values

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


来源:https://stackoverflow.com/questions/48944327/combine-date-hits-hour-hits-minute-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!