基于国家/地区的Mysql排除和包含
Posted
技术标签:
【中文标题】基于国家/地区的Mysql排除和包含【英文标题】:Mysql Exclude and Include based on countries 【发布时间】:2015-10-28 08:50:22 【问题描述】:我有一个逻辑问题需要解决。 我们有以下表格:
200
- 文章表(所有文章)
202
- 国家限制表(所有限制基于国家和文章)
如果文章在国家/地区限制表中没有结果,则该文章可以显示。
如果文章在国家限制表中有结果,但我们感兴趣的国家不存在,则该文章可以显示。
如果文章在国家限制表中有结果,并且我们感兴趣的国家存在且独占值为0,则文章可以显示。
如果文章在国家限制表中有结果,而其他国家有独占1,则该产品可以展示。
这是我的方法,但不是一个好方法...
SELECT `203`.ArtNr,
IF(
EXISTS((SELECT * FROM `202` WHERE `202`.ArtNr = `203`.ArtNr)),
'',
'yes'
) as 'Display' FROM `203`
WHERE `203`.RefNr_Search = 'GDB400'
AND `203`.ArtNr IN ('0 986 467 720','0 986 494 522','0 986 TB2 005','F 03A 150 016')
LKZ 值可以是:'RO','EU','OE'
这是这 4 篇文章的选择。上面的查询应该只返回两个结果(ArtNr=0 986 494 522,ArtNr=0 986 467 720)。我无法进行此查询...我们将不胜感激。
CREATE TABLE `203` (
`ArtNr` VARCHAR(22) NULL DEFAULT NULL,
`ArtNr_Search` VARCHAR(22) NULL DEFAULT NULL,
`DLNr` INT(4) UNSIGNED NULL DEFAULT NULL,
`SA` SMALLINT(3) UNSIGNED NULL DEFAULT NULL,
`KHerNr` INT(6) UNSIGNED NULL DEFAULT NULL,
`LKZ` VARCHAR(3) NULL DEFAULT NULL,
`RefNr` VARCHAR(22) NULL DEFAULT NULL,
`RefNr_Search` VARCHAR(22) NULL DEFAULT NULL,
`Exclude` INT(1) UNSIGNED NULL DEFAULT NULL,
`Sort` INT(5) UNSIGNED NULL DEFAULT NULL,
INDEX `ArtNr` (`ArtNr`),
INDEX `ArtNr_Search` (`ArtNr_Search`),
INDEX `RefNr` (`RefNr`),
INDEX `RefNr_Search` (`RefNr_Search`),
INDEX `KHerNr` (`KHerNr`),
INDEX `DLNr` (`DLNr`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM
ROW_FORMAT=FIXED
;
INSERT INTO `203` (`ArtNr`, `ArtNr_Search`, `DLNr`, `SA`, `KHerNr`, `LKZ`, `RefNr`, `RefNr_Search`, `Exclude`, `Sort`) VALUES ('0 986 467 720 ', '0986467720', 30, 203, 520, ' ', 'GDB400 ', 'GDB400', 0, 5);
INSERT INTO `203` (`ArtNr`, `ArtNr_Search`, `DLNr`, `SA`, `KHerNr`, `LKZ`, `RefNr`, `RefNr_Search`, `Exclude`, `Sort`) VALUES ('0 986 494 522 ', '0986494522', 30, 203, 520, ' ', 'GDB400 ', 'GDB400', 0, 5);
INSERT INTO `203` (`ArtNr`, `ArtNr_Search`, `DLNr`, `SA`, `KHerNr`, `LKZ`, `RefNr`, `RefNr_Search`, `Exclude`, `Sort`) VALUES ('0 986 TB2 005 ', '0986TB2005', 30, 203, 798, ' ', 'GDB400 ', 'GDB400', 0, 1);
INSERT INTO `203` (`ArtNr`, `ArtNr_Search`, `DLNr`, `SA`, `KHerNr`, `LKZ`, `RefNr`, `RefNr_Search`, `Exclude`, `Sort`) VALUES ('F 03A 150 016 ', 'F03A150016', 30, 203, 520, ' ', 'GDB400 ', 'GDB400', 0, 5);
CREATE TABLE `202` (
`ArtNr` VARCHAR(22) NULL DEFAULT NULL,
`DLNr` INT(4) NULL DEFAULT NULL,
`SA` INT(3) NULL DEFAULT NULL,
`LKZ` VARCHAR(3) NULL DEFAULT NULL,
`Exclude` INT(1) NULL DEFAULT NULL,
INDEX `ArtNr_LKZ` (`ArtNr`, `LKZ`)
)
COLLATE='utf8_general_ci'
ENGINE=MyISAM
ROW_FORMAT=FIXED
;
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 467 720', 30, 202, 'BR', 1);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 467 720', 30, 202, 'CDN', 1);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 467 720', 30, 202, 'USA', 1);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'ADN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'AN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'ANG', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'BF', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'BRN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'CD', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'CI', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'CM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'DJ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'DY', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'DZ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'EAK', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'EAT', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'EAU', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'ER', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'ET', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'ETH', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'GA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'GH', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'GN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'GQ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'GW', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'IL', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'IR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'IRQ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'JOR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'KM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'KWT', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'LAR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'LB', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'LS', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'MA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'MEA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'MS', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'MW', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'MZ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'OM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'Q', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RB', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RCA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RCB', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RE', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RIM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RL', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RMM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RU', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'RWA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'SA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'SN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'SP', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'ST', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'SY', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'SYR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'SZ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'TD', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'TG', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'TN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'TR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'UAE', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'WAG', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'WAL', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'WAN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'Z', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('0 986 TB2 005', 30, 202, 'ZW', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ADN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'AN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ANG', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'AS', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'BF', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'BRN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'C', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'CD', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'CI', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'CM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'CR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'DJ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'DOM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'DY', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'EAK', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'EAT', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'EAU', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ER', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ES', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ET', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ETH', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'GA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'GCA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'GH', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'GN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'GQ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'GW', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'HN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'IR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'IRQ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'JOR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'KM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'KWT', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'LAR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'LB', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'LS', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'MEX', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'MW', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'MZ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'NIC', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'OM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'PA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'Q', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RB', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RCA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RCB', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RIM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RL', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RMM', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RU', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'RWA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'SA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'SN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'SP', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ST', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'SY', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'SYR', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'SZ', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'TD', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'TG', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'UAE', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'WAG', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'WAL', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'WAN', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'Z', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ZA', 0);
INSERT INTO `202` (`ArtNr`, `DLNr`, `SA`, `LKZ`, `Exclude`) VALUES ('F 03A 150 016', 30, 202, 'ZW', 0);
【问题讨论】:
使用这种命名标准非常困难。请参考以下链接:***.com/questions/5325520/…。表格内的数据也很烦人。 @AdarshGangadharan 这是一个文章查找表,我只想根据国家(LKZ)显示其中的两行:) 【参考方案1】:得到朋友的帮助,谢谢。
SELECT distinct (`203`.ArtNr) FROM `203`
LEFT JOIN `202` ON `202`.ArtNr = `203`.ArtNr
WHERE `203`.RefNr_Search = 'gdb400'
AND `203`.ArtNr IN ('0 986 467 720','0 986 494 522','0 986 TB2 005','F 03A 150 016')
AND (`202`.ArtNr IS NULL OR (`202`.Exclude = 0 AND `202`.LKZ IN('RO','EU','OE')) OR (`202`.Exclude = 1 AND `202`.LKZ NOT IN('RO','EU','OE')))
【讨论】:
以上是关于基于国家/地区的Mysql排除和包含的主要内容,如果未能解决你的问题,请参考以下文章
如何使用logstash使用Mobile_Number添加基于手机号码的国家/地区名称字段