Getting syntax error on CAST & COALESCE function

49 views Asked by At
SELECT
    CAST(purchase_price AS FLOAT64)
FROM
    'peppy-generator-406617.customer_data.customer_purchase'
ORDER BY
    CAST(purchase_price AS FLOAT64) DESC

I tried to get the purchase price in ascending order but I got syntax error. I could not understand the reason for getting the error. Need help to understand the mistake.

2

There are 2 answers

2
ömer yılmaz On
SELECT
    CAST(purchase_price AS FLOAT64) AS x1
FROM
    'peppy-generator-406617.customer_data.customer_purchase'
ORDER BY
    x1 DESC
0
Schwern On

You're using a string for a table name. Table and column names are identifiers; identifiers are quoted differently. Either use no quotes, or use `to quote.

To avoid repeating column expressions, you can refer to columns by their position in the select clause.

SELECT
    CAST(purchase_price AS FLOAT64)
FROM
    `peppy-generator-406617.customer_data.customer_purchase`
ORDER BY 1 DESC