如何编写一个查询而不是这三个? 谢谢你的回答!
sqlCtx.sql("""Select count(*) as iPhone
from yahoo
where source like '%iphone%'
""").show()
sqlCtx.sql("""Select count(*) as Android
from yahoo
where source like '%android%'
""").show()
sqlCtx.sql("""Select count(*) as Web
from yahoo
where source like '%Web Client%'
""").show()
答案 0 :(得分:0)
你需要尝试相同的条件,如果存在则添加1,否则添加0,这是样本: -
sqlCtx.sql("""
Select
sum(if source like '%iphone%', 1, 0) as Iphone,
sum(if source like '%android%', 1, 0) as Android,
sum(if source like '%Web Client%', 1, 0) as Web
from yahoo
""").show()