left join達不到想要的效果,得到的不是左表的樣本數,原因在這!!!
阿新 • • 發佈:2019-01-29
1)區別:左表 left join 右表 on/where
left join 是以左表為主,on是不管條件滿不滿足,都會保留左表的內容,而where,則是將不滿足條件的過濾掉了;
2)左表 left join 右表 on 的時候,左表和右表都必須去重,並且都必須保證on條件後面用到的列不會為null,否則,你left join得到的樣本數永遠不會是左表樣本數,得到一個奇怪的數。特別注意,left join 對兩個表的要求比較高:去重,無null值;
select * from student join takes on students.ID = takes.ID與
select × from student,takes where students.ID = takes.ID 等價;
但與select * from student join takes where students.ID = takes.ID 有區別
dfh71 = sqlContext.sql("select h7._c0 as company_name,h6.company_name as add_company_name from h7 left join h6 on h7._c0 = h6.company_name ")
dfh71.createOrReplaceTempView('h71')
dfh72 = sqlContext.sql("select h71.company_name from h71 where add_company_name != company_name ")
dfh72.repartition(1).write.csv(os.path.join(myfeature_path, " temp_the_lost_shixin_features.csv"),
mode='overwrite', header=True)
dfh72 = sqlContext.sql("select h71.company_name from h71 where add_company_name != company_name ")
語句用 不等於 !=最後得到個空表;需要用add_company_name is null