Spark SQL Case statement - Stack Overflow
stackoverflow.com › spark-sql-case-statement1 day ago · %%python from pyspark.sql.functions import explode, sequence, to_date beginDate = '2023-01-01' endDate = '2025-12-31' ( spark.sql (f"select explode (sequence (to_date (' {beginDate}'), to_date (' {endDate}'), interval 1 day)) as calendarDate") .createOrReplaceTempView ('dates') ) %%sql select calendarDate , month (calendarDate) monthNum , case …
How to do "case when exists..." in spark sql - Stack Overflow
stackoverflow.com › questions › 67815403Jun 3, 2021 · Select a.id, Case When IsNull(b.id) Then 'N' else 'Y' end as Col_1 From A Left Outer Join (Select distinct id from tableb) b On A.id=b.id That way you are not repeatedly executing a lookup query for every id in A. Addition Your comment indicated that you are trying to create multiple Y/N columns based on b values. Your example had a Y/N for col1 when there was a 1,2,3 and a Y/N for col2 when there was a 4,5,6.