1

I am trying to use agg functions to query data, I have space in the column name in SNOWFLAKE

select item, avg(item price) from order group by item; 

The error is

Numerical value '1212.11' is not recognized 

Expected output is

Code which gives item and avg price of that item

1
  • Why not alter the table to fix the column name instead? Commented Jan 31, 2023 at 19:14

2 Answers 2

1

Try

select item, try_to_number(avg("item price")) from order group by item;

Sign up to request clarification or add additional context in comments.

Comments

0

If you try add " (double quotes) around the column name does that help?

select item, avg("item price"::INT) from order group by item; 

The ::INT just casts it to a datatype that can be summed. You should take a peak at the datatypes available to find one that best suits your needs. (2 dp might be good for currency)

Another possibility is :

select item, avg( price ) from order group by item; 

That's if you don't have a column called "item price" rather 2 columns "item" and "price".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.