diff --git a/python/pyspark/sql/column.py b/python/pyspark/sql/column.py index a38ed64eb700..0ac71b19cd15 100644 --- a/python/pyspark/sql/column.py +++ b/python/pyspark/sql/column.py @@ -1578,6 +1578,24 @@ def outer(self) -> "Column": -------- pyspark.sql.dataframe.DataFrame.scalar pyspark.sql.dataframe.DataFrame.exists + + Examples + -------- + >>> from pyspark.sql import functions as sf + >>> employees = spark.createDataFrame( + ... [(1, "Alice", 5000, 101), (2, "Bob", 6000, 101), (3, "Charlie", 4500, 102)], + ... ["id", "name", "salary", "department_id"], + ... ) + >>> employees.alias("e1").where( + ... sf.col("salary") > employees.alias("e2").where( + ... sf.col("e2.department_id") == sf.col("e1.department_id").outer() + ... ).select(sf.avg("salary")).scalar() + ... ).select("name", "salary", "department_id").orderBy("name").show() + +----+------+-------------+ + |name|salary|department_id| + +----+------+-------------+ + | Bob| 6000| 101| + +----+------+-------------+ """ ...