进行双重联接以整理子类别
我正在编写一个联接以从另一个表中获取子类别。但是我的问题是子类别没有唯一的ID。子类别由xncatcode
和catid
组成。它们都在sub_cat
表中。当您查看producten
表时,会看到xngroupcode
(类别)和xncatdesc
(子类别)。
我现在面临的问题是我找回了正确的productgroup
。但是错误的sub_cat
。看到我分别加入了他们(我认为)
SELECT DISTINCT
*
FROM
froets.producten
left JOIN froets.productcategorieën as PGROUP
on froets.PGROUP.productcategorienummer = froets.producten.xngroupcode
left JOIN froets.sub_cat as PCAT
on froets.producten.xncatncode = froets.PCAT.subcatid
left JOIN froets.sub_cat as SCAT
on froets.SCAT.catid = froets.PGROUP.productcategorienummer
WHERE
froets.producten.itemdesc LIKE '%flessen%'
or froets.producten.brand like '%flessen%'
Extra data
:)
在producten
表中,所有产品都包含xncatcode
和xngroupcode
(它们都在sub_cat
中)。所以有可能加入他们there
。
# id, model, itemcode, itemdesc, extdesc, itemkeywords, size, sizegrid, gender, weightgr, lengthcm, heightcm, widthcm, diametercm, sizecombined, qtypercarton, decopackagingindiv, decopackagingindivtype, decopackaging, grossweightkg, nettweightkg, exportlcm, exportwcm, exporthcm, countryoforigin, hscode, impallmethods, impmethoddefault, impallpositions, imppositiondefault, imppositionsimpledefault, impwidthdefaultmm, impheightdefaultmm, impdiameterdefaultmm, impsizedefaultmm, maxcoloursdefault, brand, xngroupcode, xngroupdesc, xncatncode, xncatdesc, colordesc, simplecolor, pmscolorreference, basiccolor, peninkcolor, material, batterytype, features, bestseller, eancode, thematicitem, compliances, imagemain, imagedecoy1, imagedecoy2, imagedecoy3, imagepackage, imagefront, imageback, imageextra1, imageextra2, imageextra3, imagedetail1, imagedetail2, imagedetail3, imageprintlinesdefault, marksegment, maincat, eoycat, launchdate, language, hexcolor, imagegroup, imagemood1, imagemood2, imagemood3, imagemodel, videourl1, videourl2, newitem, id, productcategorienaam, productcategorienummer, productcategoriegroep, GroepAfbeelding, id, naam, subcatid, catid, id, naam, subcatid, catid
'44870', '104231', '10423100', 'zaklamp flessenopener', 'Omega zaklamp. Aluminium. ', 'Lamp, lampen, zaklamp, zaklampen, lantaarn, lantaarns, zaklantaarn, zaklantaarns, veiligheidslamp, veiligheidslampen,', '', '', 'None', '48', '', '10', '', '2,5', '10 x Ø 2,5 cm', '200', 'No', '', '10 / Joined bubble bag', '12', '11,4', '32', '34', '24', 'China (volksrepubliek)', '8513100000000000000000', 'Tampondruk, Lasergraveren', 'Tampondruk', 'romp', 'Lamp left, button top,On colored part', 'romp', '35', '10', '', '35 x 10 mm', '4', 'Bullet', '12', 'Tools & Torches', '1', 'Zaklampen', 'Gun metal', 'Midden grijs', '', 'Grijs', '', 'Aluminium.', '', '', '', '8713159202448', 'GUNMETAL', 'Batterijrichtlijn, WEEE, RoHS , Getest op cadmium ', '10423100.jpg', '10423100_PP_Y1.jpg', '', '', '', '10423100_F1.jpg', '', '', '10423100_E2.jpg', '', '', '', '', '10423100_1_1297_1927.jpg', 'Bullet', 'N', 'N', 'JAN16', 'NL', '6F6E71', '', '', '', '', '', '', '', 'false', '20', 'Tools & Torches', '12', NULL, '', '1', 'Sweat Shirts', '1', '21', '20', 'Auto accessoires', '3', '12'
'44870', '104231', '10423100', 'zaklamp flessenopener', 'Omega zaklamp Aluminium. ', 'Lamp, lampen, zaklamp, zaklampen, lantaarn, lantaarns, zaklantaarn, zaklantaarns, veiligheidslamp, veiligheidslampen,', '', '', 'None', '48', '', '10', '', '2,5', '10 x Ø 2,5 cm', '200', 'No', '', '10 / Joined bubble bag', '12', '11,4', '32', '34', '24', 'China (volksrepubliek)', '8513100000000000000000', 'Tampondruk, Lasergraveren', 'Tampondruk', 'romp', 'Lamp left, button top,On colored part', 'romp', '35', '10', '', '35 x 10 mm', '4', 'Bullet', '12', 'Tools & Torches', '1', 'Zaklampen', 'Gun metal', 'Midden grijs', '', 'Grijs', '', 'Aluminium.', '', '', '', '8713159202448', 'GUNMETAL', 'Batterijrichtlijn, WEEE, RoHS , Getest op cadmium ', '10423100.jpg', '10423100_PP_Y1.jpg', '', '', '', '10423100_F1.jpg', '', '', '10423100_E2.jpg', '', '', '', '', '10423100_1_1297_1927.jpg', 'Bullet', 'N', 'N', 'JAN16', 'NL', '6F6E71', '', '', '', '', '', '', '', 'false', '20', 'Tools & Torches', '12', NULL, '', '1', 'Sweat Shirts', '1', '21', '33', 'Gereedschapssetjes', '2', '12'
'44870', '104231', '10423100', 'zaklamp flessenopener', 'Omega zaklamp Aluminium. ', 'Lamp, lampen, zaklamp, zaklampen, lantaarn, lantaarns, zaklantaarn, zaklantaarns, veiligheidslamp, veiligheidslampen,', '', '', 'None', '48', '', '10', '', '2,5', '10 x Ø 2,5 cm', '200', 'No', '', '10 / Joined bubble bag', '12', '11,4', '32', '34', '24', 'China (volksrepubliek)', '8513100000000000000000', 'Tampondruk, Lasergraveren', 'Tampondruk', 'romp', 'Lamp left, button top,On colored part', 'romp', '35', '10', '', '35 x 10 mm', '4', 'Bullet', '12', 'Tools & Torches', '1', 'Zaklampen', 'Gun metal', 'Midden grijs', '', 'Grijs', '', 'Aluminium.', '', '', '', '8713159202448', 'GUNMETAL', 'Batterijrichtlijn, WEEE, RoHS , Getest op cadmium ', '10423100.jpg', '10423100_PP_Y1.jpg', '', '', '', '10423100_F1.jpg', '', '', '10423100_E2.jpg', '', '', '', '', '10423100_1_1297_1927.jpg', 'Bullet', 'N', 'N', 'JAN16', 'NL', '6F6E71', '', '', '', '', '', '', '', 'false', '20', 'Tools & Torches', '12', NULL, '', '1', 'Sweat Shirts', '1', '21', '47', 'Zakmes', '4', '12'
'44870', '104231', '10423100', 'zaklamp flessenopener', 'Omega zaklamp Aluminium. ', 'Lamp, lampen, zaklamp, zaklampen, lantaarn, lantaarns, zaklantaarn, zaklantaarns, veiligheidslamp, veiligheidslampen,', '', '', 'None', '48', '', '10', '', '2,5', '10 x Ø 2,5 cm', '200', 'No', '', '10 / Joined bubble bag', '12', '11,4', '32', '34', '24', 'China (volksrepubliek)', '8513100000000000000000', 'Tampondruk, Lasergraveren', 'Tampondruk', 'romp', 'Lamp left, button top,On colored part', 'romp', '35', '10', '', '35 x 10 mm', '4', 'Bullet', '12', 'Tools & Torches', '1', 'Zaklampen', 'Gun metal', 'Midden grijs', '', 'Grijs', '', 'Aluminium.', '', '', '', '8713159202448', 'GUNMETAL', 'Batterijrichtlijn, WEEE, RoHS , Getest op cadmium ', '10423100.jpg', '10423100_PP_Y1.jpg', '', '', '', '10423100_F1.jpg', '', '', '10423100_E2.jpg', '', '', '', '', '10423100_1_1297_1927.jpg', 'Bullet', 'N', 'N', 'JAN16', 'NL', '6F6E71', '', '', '', '', '', '', '', 'false', '20', 'Tools & Torches', '12', NULL, '', '1', 'Sweat Shirts', '1', '21', '48', 'Zaklampen', '1', '12'
'44870', '104231', '10423100', 'zaklamp flessenopener', 'Omega zaklamp Aluminium. ', 'Lamp, lampen, zaklamp, zaklampen, lantaarn, lantaarns, zaklantaarn, zaklantaarns, veiligheidslamp, veiligheidslampen,', '', '', 'None', '48', '', '10', '', '2,5', '10 x Ø 2,5 cm', '200', 'No', '', '10 / Joined bubble bag', '12', '11,4', '32', '34', '24', 'China (volksrepubliek)', '8513100000000000000000', 'Tampondruk, Lasergraveren', 'Tampondruk', 'romp', 'Lamp left, button top,On colored part', 'romp', '35', '10', '', '35 x 10 mm', '4', 'Bullet', '12', 'Tools & Torches', '1', 'Zaklampen', 'Gun metal', 'Midden grijs', '', 'Grijs', '', 'Aluminium.', '', '', '', '8713159202448', 'GUNMETAL', 'Batterijrichtlijn, WEEE, RoHS , Getest op cadmium ', '10423100.jpg', '10423100_PP_Y1.jpg', '', '', '', '10423100_F1.jpg', '', '', '10423100_E2.jpg', '', '', '', '', '10423100_1_1297_1927.jpg', 'Bullet', 'N', 'N', 'JAN16', 'NL', '6F6E71', '', '', '', '', '', '', '', 'false', '20', 'Tools & Torches', '12', NULL, '', '1', 'Sweat Shirts', '1', '21', '49', 'Meetlinten', '8', '12'
'44870', '104231', '10423100', 'zaklamp flessenopener', 'Omega zaklamp Aluminium. ', 'Lamp, lampen, zaklamp, zaklampen, lantaarn, lantaarns, zaklantaarn, zaklantaarns, veiligheidslamp, veiligheidslampen,', '', '', 'None', '48', '', '10', '', '2,5', '10 x Ø 2,5 cm', '200', 'No', '', '10 / Joined bubble bag', '12', '11,4', '32', '34', '24', 'China (volksrepubliek)', '8513100000000000000000', 'Tampondruk, Lasergraveren', 'Tampondruk', 'romp', 'Lamp left, button top,On colored part', 'romp', '35', '10', '', '35 x 10 mm', '4', 'Bullet', '12', 'Tools & Torches', '1', 'Zaklampen', 'Gun metal', 'Midden grijs', '', 'Grijs', '', 'Aluminium.', '', '', '', '8713159202448', 'GUNMETAL', 'Batterijrichtlijn, WEEE, RoHS , Getest op cadmium ', '10423100.jpg', '10423100_PP_Y1.jpg', '', '', '', '10423100_F1.jpg', '', '', '10423100_E2.jpg', '', '', '', '', '10423100_1_1297_1927.jpg', 'Bullet', 'N', 'N', 'JAN16', 'NL', '6F6E71', '', '', '', '', '', '', '', 'false', '20', 'Tools & Torches', '12', NULL, '', '3', 'Outdoor Fleece', '1', '23', '20', 'Auto accessoires', '3', '12'
如何获得正确的子类别:)?
答案 0 :(得分:1)
如果我正确地跟随了您,则您似乎在子类别上缺少JOIN条件。
此:
LEFT JOIN froets.sub_cat as PCAT
ON froets.producten.xncatncode = froets.PCAT.subcatid
应写为:
LEFT JOIN froets.sub_cat as PCAT
ON froets.producten.xncatncode = froets.PCAT.subcatid
AND froets.producten.xngroupcode = froets.PCAT.catid