I am using the below query in my server and I need to make the columns to be dynamic and not String. I tried to use:
UNNEST(GENERATE_DATE_ARRAY('2024-03-12', '2024-03-25', INTERVAL 1 DAY))
But I got the error:
Syntax error: Unexpected keyword UNNEST
What is the alternative?
(
SELECT * FROM
( SELECT
DATE(Date) AS Date,
Region,
Revnue
FROM
`analy-417.AM.Overview` where 2 is not null
)
PIVOT(sum(Revnue) FOR Date IN ('2024-03-25','2024-03-24','2024-03-23','2024-03-22','2024-03-21','2024-03-20','2024-03-19','2024-03-18','2024-03-17','2024-03-16','2024-03-15','2024-03-14','2024-03-13','2024-03-12'))
)
Here's an alternative using left join unnest instead of having to write out all the dates. Made a mock table to how the results in the CTE/with function.