【问题标题】:How to use case statements to return different pulls in sql?如何使用 case 语句在 sql 中返回不同的 pull?
【发布时间】:2020-11-14 13:22:27
【问题描述】:

我正在使用 presto SQL 并尝试制作它,以便我可以根据用户输入执行不同的选择语句。我当前的代码结构如下所示:

SELECT (case when input in ('A', 'B', 'C') then (SELECT * from table1)
             when input in ('D', 'E', 'F') then (SELECT * from table2)
             when input in ('G', 'H', 'I') then (SELECT * from table3)
             ...
        end)

执行此操作时,我收到一条错误消息,提示我无法返回包含多列的子查询。有没有办法使用这种结构或其他方法来完成单独的选择语句?

谢谢

【问题讨论】:

    标签: sql presto apache-zeppelin


    【解决方案1】:

    假设表有相同的列,使用union all:

    select t.*
    from table1 t
    where input in ('A', B', 'C')
    union all
    select t.*
    from table2 t
    where input in ('D', E', 'F')
    union all
    . . .
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多