on-internet
← Community

Pyspark SQL: How to do GROUP BY with specific WHERE condition

Stack Overflow ·

So I am doing some SQL aggregation transformations of a dataset and there is a certain condition that I would like to do, but not sure how. Here is a basic code block: le_test = spark.sql(""" SELECT Country, ROUND(MIN(Life_Expectancy)) AS Min_LE, ROUND(AVG(Life_Expectancy)) AS Avg_LE, ROUND(MAX(Life_Expectancy)) AS Max_LE, ROUND(MAX(Life_Expectancy) - MIN(Life_Expectancy)) AS LE_range FROM le_cleaned GROUP BY Country """) This dataset has countries split up by years (over the course of about two decades), hence the aggregation. What I want to do is an additional column based on the difference

Comments

Sign in or sign up to comment and upvote.

No comments yet.