[英]Index - Match like function in PL-SQL
好了,您可以使用聚合:
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.