将两列中的值与子查询中两列的值进行匹配

时间:2017-10-19 08:04:28

标签: sql db2

我有一个问题我无法理解,即使我认为我有解决方案。

顺便说一下,我认为这是DB2 SQL。

我有一个客户编号和一个国家/地区代码(使用B1从字符串中提取),我不想在子查询中组合查找,如下所示:

SUBSTR

不在下面的结果中

SELECT    ku.orgnr                             AS customer , 
          Substr(bu.bank_account_swiftadr,5,2) AS country 
FROM      db811.bet_utl bu 
LEFT JOIN db811.henv_utl bh 
ON        bu.betaling_urn = bh.betaling_urn 
LEFT JOIN db811.betaling_status bs 
ON        bu.betaling_status = bs.betaling_status 
LEFT JOIN db811.kunde_orgnr ku 
ON        bu.kundenr = ku.kundenr 
WHERE     bu.kanal = 'N' 
AND       (ku.orgnr, Substr(bu.bank_account_swiftadr,5,2)) ;

这应该适用于我,但它似乎只匹配其中一个,我需要两个都是真的,以便我用SELECT ku.orgnr AS customer , Substr(bu.bank_account_swiftadr,5,2) AS country , COUNT(*) AS numberof FROM db811.bet_utl_hist bu LEFT JOIN db811.kunde_orgnr ku ON bu.kundenr = ku.kundenr WHERE and bu.kanal = 'N' AND bu.betalingsdato > '2016-01-01' GROUP BY ku.orgnr , substr(bu.bank_account_swiftadr,5,2);

排除它

我认为我错过了一些基本的东西,因为我对此很陌生。

0 个答案:

没有答案