Company
Date Published
Author
Roel Peters
Word count
1413
Language
English
Hacker News points
None

Summary

You were deep in an analytical flow, firing off every question that you think Snowflake DB can answer – and then, it happened. You got the unnecessarily terse and unexpectedly confusing error, “blah blah blah is not a valid group by expression.” This error occurs when there's something in your query's GROUP BY clause that's not supposed to be there, typically due to omitted or incorrectly added code, leading to either a slip or a mistake. Two common causes of this error are adding an aggregated column to the GROUP BY function and referring to unaggregated columns in a Window function without using them in the GROUP BY clause. The Snowflake dialect supports combining both GROUP BY and Window functions, but there's a warning about compatibility issues with PARTITION BY and GROUP BY. To resolve these errors, you can either match up the column names or use an aggregation function to introduce compatibility, or use a CTE to calculate the sum of revenue per customer ID and order status without needing a GROUP BY clause.