Skip to content

line_item.value is not a valid group by expression

I currently have two columns which is the result after flattening a json file in snowsql

I want to introduce a third column that shows total discount for a particular id

Following is my code:

However, this gives error that [LINE_ITEM.VALUE] is not a valid group by expression

Advertisement

Answer

If you need to have some additional “total” (of any kind, supported functions are listed in the documentation) column along with your original columns, you need to use analytical function here.

This way you need to put all the column to aggregate by in partition by <column list> clause and you do not need a group by.

Also it’s possible to calculate totals on totals with

where the first sum calculates total grouped by group_by_cols and the second (outer) sum calculates an analytical function (totals) on aggregated result by columns_to_total_by. One notice: both display_cols and columns_to_total_by should be in group_by_cols columns since group by is executed first).

User contributions licensed under: CC BY-SA
10 People found this is helpful