【问题标题】:conditional select inside select选择内的条件选择
【发布时间】:2021-11-07 22:02:49
【问题描述】:
select t.col1,b.somecolumn t.col2,a.col1,VQ.a,VQ.b,VQ.e,VQ.d,VQ.f,  
   (select t.status as a, p.id as b,p.permit as c, p.des as d, p.error_code as e, p.cause as f
   from table_A t 
   inner join table_B p on t.a = p.a 
   where p.c = 'license' and t.status = 'Fail') as VQ
  from table_A t 
  join table_C a on t.col1 = a.asset_id
  join table_B b on t.somecolumn = b.somecolumn ;
   
   

当我执行上面的代码时,我遇到了错误

SQL Error [42601]: ERROR: navigation on column "vq" is not allowed as it is not SUPER type

我正在尝试在 select 中进行选择。

【问题讨论】:

  • 请解释你想要完成的逻辑。样本数据和期望的结果会有所帮助。

标签: sql postgresql select subquery


【解决方案1】:

您似乎想从相关子查询中返回多个列。如果是这样,您可以使用lateral join

select t.col1, b.somecolumn t.col2, a.col1, vq.*
from table_A t join
     table_C a
     on t.col1 = a.asset_id join
     table_B b
     on t.somecolumn = b.somecolumn left join lateral
     (select t.status as a, p.id as b,p.permit as c, p.des as d, p.error_code as e, p.cause as f
      from table_A t join
           table_B p on t.a = p.a 
      where p.c = 'license' and t.status = 'Fail'
     ) vq
     on 1=1;

   

【讨论】:

    猜你喜欢
    • 2013-04-20
    • 1970-01-01
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 2017-03-30
    相关资源
    最近更新 更多