Snowflake Vs MS-SQL - Part 8 - The value of another column for MAX value

     


The value of another column for MAX value

Suppose you have a data as below and if you want to get the details of another columns like employee_id based on MAX salary.


MS-SQL Server 

You can achieve this by writing query in multiple ways. One of the ways is writing sub query. 



There is NO direct way to achieve this.


However in Snowflake we can achieve this by using Aggregate function MAX_BY.



This query will return a record Employee_id = 900.

But there is a catch in this function, if there more than one row contains the maximum value for the salary column, the function is non-deterministic and might return the employee ID for a different row in subsequent executions.

For more details, you can refer the following LINK.

On similar line there is function MIN_BY.


Comments

Popular posts from this blog

Snowflake Vs MS-SQL - Part 36 - SPLIT_TO_TABLE

Snowflake Vs MS-SQL - Part 63 - ON Clause & Cross Join

Snowflake Vs MS-SQL - Part 33 - INITCAP