Support Questions

Find answers, ask questions, and share your expertise

Assigning aggregate value from a pySpark Query/data frame to a variable

New Contributor

We have a requirement in pySpark where an aggregated value from a SQL query is to be stored in a variable and that variable is used for SELECTion criteria in subsequent query. For ex: get the max(sales_date) and get the data from table for that date. Can you please share some inputs on this?

Regards,

Phaneendra

1 REPLY 1

Rising Star

You can retrieve the value of the aggregate query like this:

aggr_value = df.select("your query").collect()[0][0]

then you can use it in the next queries as any variable.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.