由于NULL值而创建MySQL视图

时间:2012-11-07 11:13:24

标签: mysql

我尝试设置以下VIEW并定义了3个导致WHERE子句中2个表的列之间指定匹配的情况。

这或多或少有效,因为视图中的条目应该因我的声明而被排除。请查看带有select *输出的屏幕截图。

你能在这帮我吗?非常感谢。

CREATE OR REPLACE VIEW `match` AS SELECT 
a.`werksnr`,
b.`werksnr` AS `werksnr_ref`, 
a.`EAN`,
b.`EAN` AS `EAN_ref`, 
a.`lieferant`,
b.`lieferant` AS `lieferant_ref`, 
a.`artikel`, 
b.`artikel` AS `artikel_ref`,  
a.`artikelbezeichnung` AS `bezeichnung_suspect`,
b.`artikelbezeichnung1`, 
b.`artikelbezeichnung2`

FROM suspect as a, reference as b WHERE 

(a.EAN IS NOT NULL AND b.EAN IS NOT NULL AND a.werksnr IS NOT NULL and b.werksnr IS NOT NULL AND a.EAN = b.EAN AND a.werksnr = b.werksnr) OR
(a.lieferant IS NOT NULL AND b.lieferant IS NOT NULL AND a.werksnr IS NOT NULL AND b.werksnr IS NOT NULL AND a.lieferant = b.lieferant AND a.werksnr = b.werksnr) OR
(a.lieferant IS NOT NULL AND b.lieferant IS NOT NULL AND a.EAN IS NOT NULL AND b.EAN IS NOT NULL AND a.lieferant = b.lieferant AND a.EAN = b.EAN);

screenshot

0 个答案:

没有答案