繁体   English   中英

索引-PL-SQL中的类似匹配函数

[英]Index - Match like function in PL-SQL

最近,我对从数据仓库获取的数据有非常具体的问题。 问题已解决,但我必须编辑控制环境一段时间。

我们有关于收到的发票的数据,但是由于某种原因,有关每张发票的信息分为两行:第一行具有重要列unique_code_Avendor_number ,第二行具有重要列unique_code_Bamount 因此,每张发票都有非常特定的唯一代码,并且必须使用此代码以某种方式将两行中的信息结合起来,如您在图片中所见。

我的桌子看起来和我想看的行

好了,您可以使用聚合:

select date_key, invoice_type,
       max(case when unique_code_b is null then unique_code_a end) as unique_code_a,
       max(unique_code_b) as unique_code_b,
       max(case when unique_code_b is null then vendor_number end) as vendor_number,
       max(case when unique_code_b is not null then amount end) as amount
from t
group by date_key, invoice_type;

编辑:

如果可以使用唯一代码进行匹配,那么我建议:

select date_key, invoice_type,
       coalesce(unique_code_a, unique_code_b) as unique_code,
       max(case when unique_code_b is null then vendor_number end) as vendor_number,
       max(case when unique_code_b is not null then amount end) as amount
from t
group by date_key, invoice_type, coalesce(unique_code_a, unique_code_b);

根据您所说的,自我加入可能应该起作用:

SELECT 
    A.DATE_KEY,
    A.INVOICE_TYPE,
    A.UNIQUE_CODE_A,
    B.UNIQUE_CODE_B,
    A.VENDOR_NUMBER,
    B.AMOUNT
FROM MyTable A 
INNER JOIN MyTable B ON A.UNIQUE_CODE_A=B.UNIQUE_CODE_B

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM