php—编写双连接以获取产品的子类别

gmxoilav  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(379)

使用双连接来整理子类别
我正在编写一个连接来从另一个表中获取子类别。但是我的问题是子类别没有唯一的id xncatcode 以及 catid 一起。他们都在公园里 sub_cat table。当你看着 producten 你看到table了吗 xngroupcode (cat)和 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'

如何才能取回正确的子类别:)?
taor4pac

taor4pac1#

如果我没记错的话,你似乎在子类别上缺少一个连接条件。
这是:

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

相关问题