I am using BigQuery to query Google Analytics and pull out Transaction ID's by time. I am having difficulty creating a usable datetime field with the columns provided. Using the query below, the closest I have been able to get is "2019-02-11T19:00:00" Which does not include the minutes. (seconds are unimportant)
SELECT PARSE_DATETIME('%Y%m%d%H', newtime) AS datetime, orderid
FROM
(SELECT CONCAT(date, newhour, newminute) AS newtime
, Orderid
FROM
(SELECT date
, CAST(h.hour AS STRING) AS NewHour
, CAST(h.minute AS STRING) AS Newminute
, h.transaction.transactionId AS Orderid
FROM `analyticsdata*` LEFT JOIN UNNEST(hits) as h
WHERE h.transaction.transactionId!= ''))
The problems I have faced so far: The hits.minute column returns a single digit if < 10 causing the parse to fail on any fields with only 13 digits. I am unable to left pad as the hits field is a nested array.
Below is the data as it appears without formatting:
| Date | Hour | Minute | Order|
|20191010 | 12 | 7 | 12345|
How I would like it to appear:
| datetime | Order |
|2019-10-10T12:07:00 | 12345 |