Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
672 views
in Technique[技术] by (71.8m points)

google bigquery - Extract hour of the day from a timestamp in Big Query SQL ('FROM' error)

I want to extract the hour of the day from the created_at timestamp (line 3) in the second column via Big Query SQL. With my current code I get the error: "Encountered " "FROM" "FROM "" at line 3, column 18. Was expecting: ")" ..."

Current code:

 SELECT 
    date(created_at) as date,
    EXTRACT(HOUR FROM created_at) AS hour,
    sum(net_revenue) as net_revenue, 
    count(order_unique_id) as orders  
    FROM [source]
    WHERE DATE(created_at) BETWEEN DATE(DATE_ADD(CURRENT_DATE(), -2, 'DAY')) AND CURRENT_DATE()
    GROUP BY 1,2

Thanks in advance for helping!

question from:https://stackoverflow.com/questions/65844948/extract-hour-of-the-day-from-a-timestamp-in-big-query-sql-from-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The only error I see in your query is in the WHERE clause. Presumably you intend:

WHERE DATE(created_at) BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL -2 DAY') AND CURRENT_DATE()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...