将sql代码转换为pyspark代码的问题

ax6ht2ek  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(319)

我需要将下面的sql代码转换为pysparkDataframe代码,而不是spark.sql('code')代码。

select * from table1 where 
(
case when clm1 in ('R','C', 'F') then l=1 
when clm1 in ('8','8-B') 
and (select coalesce(max (code),0) from table2 where clm2 = "XXX') = 0 then 1=2
else 1=2 end)

如何在where条件下使用case条件。。。

bfhwhh0e

bfhwhh0e1#

假设上面是工作查询-

df.where("case when clm1 in ('R','C', 'F') then l=1 when clm1 in ('8','8-B') and (select coalesce(max (code),0) from table2 where clm2 = "XXX') = 0 then 1=2 else 1=2 end")

相关问题