如何 select 并计算同一查询中同一列中的3个元素并将它们显示在三列中?

How to select and count 3 elements in the same column in the same query and show them in three columns?

如何写一个查询而不是这三个? 感谢您的回答!

    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()

您需要尝试相同的条件,如果存在则加 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()