【问题标题】:Merge two table with different columns without null values合并具有不同列的两个表,没有空值
【发布时间】:2020-04-01 10:24:12
【问题描述】:

再次在这里寻求帮助 - 我正在使用两个 Oracle 表

我有这个问题 (image-1)

有两个不同列的表,我做了一个联合,我得到了你在 image-1 上看到的结果 这是我的查询:

(select td.DETALLE col1, 
           tg.FININ col2, 
           tg.ffinn col3,
           null as col4
    from table_1 tg
    inner join other_table td on (tg.cod_f = td.fol and tg.prod_c = td.prod)
    where UPPER(tg.sys_user) = UPPER(:APP_USER)
      and td.fol = :P10_FOLLETO
      and td.prod = :P10_PRODUCTO
      and tg.fin = :P10_FECHA_INICIO)
    union all 
    (select null as col1
          ,null as col2
          ,null as col3
          ,camp.camp_util.get_data(:P10_FOLLETO, :P10_PRODUCTO, :P10_FECHA_INICIO) as col4 -- This is a FUNCTION from another schema that will return in this case just MAD
    from dual);

但我的结果可能是:

注意:每个查询都将返回一行,因此我想将所有内容分组在一行中。

有人帮帮我吗?

问候

【问题讨论】:

  • 这里的大多数人都希望样本表数据和预期结果为格式化文本,而不是图像。
  • 再添加几行样本数据,并相应调整结果。

标签: sql oracle plsql oracle-apex oracle-apex-5.1


【解决方案1】:

我认为您不想要union,而是需要调用函数的单个选择:

select td.DETALLE col1, 
       tg.FININ col2, 
       tg.ffinn col3,
       camp.camp_util.get_data(:P10_FOLLETO, :P10_PRODUCTO, :P10_FECHA_INICIO) as col4
from table_1 tg
inner join other_table td on (tg.cod_f = td.fol and tg.prod_c = td.prod)
where UPPER(tg.sys_user) = UPPER(:APP_USER)
  and td.fol = :P10_FOLLETO
  and td.prod = :P10_PRODUCTO
  and tg.fin = :P10_FECHA_INICIO

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-18
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多