Debayan
Databricks Employee
Databricks Employee

Hi, Have you tried using the aggregate function which may help in this case?

https://docs.databricks.com/sql/language-manual/functions/aggregate.html