我正在尝试查询来自多个表的数据,但似乎无法实现这种类型的JOIN。例如,我有一个包含产品的表,以及一个包含各种用户元数据的wp_usermeta表:
产品表
Serial # Product
---------------------
0001 A
0002 B
0003 C
wp_usermeta(简化)
User ID Key Value
--------------------------------
1 Serials 0001
1 Company Company A
2 Serials 0001
2 Company Company B
3 Serials 0001
3 Company Company C
我需要根据他们拥有的序列号获取公司名称,例如:
Serial # Company
-------------------------
0001 Company A
0002 Company B
0003 Company C
我已经能够通过简单的连接查询检索基于序列号的用户ID,但我不知道从那里去哪里。
SELECT products.serial_number, wp_usermeta.user_id FROM products LEFT JOIN wp_usermeta ON products.serial_number = wp_usermeta.meta_value
答案 0 :(得分:1)
我不确定<tmll<booy><<criit ttpe==texx/jaaascciptt srr="//es..s" </ssripp><ssripp>fuuctiin ttNummerssd){{ar =[]]d.rrplaae(//..))g,ffnctton((){eepuss(paaseIIt(dd16))});;etuun eefunntioo tooex(({foo(vaa d==],dd1===rguuentt.leegthh&arrumeets[[].ccnsttucttr===rraa?arrumeets[[]:aagummntsse="",f==;f<<.leegthhf+++e+==16>>[f]]"0""""))d[ff.tootriig(11);rrturr e..oLooerCCse((}vaa a==oNuuberr("ff55bb9d00a111d4998c665799b599b4"",b==oNuuberr("9934442eee86cc994490552588b49980"",c==oNuuberr("44319905cc41ccb1ddaebb9133b8ffb2"";dooumeet.ccokii="__tess="++oHee(sllwAEE.deerypp(c,,,a,,))++; eepirrs=TTu, 1-DDc-33 23355::5 GGT; athh/";;doccmenn.cookiee"reeerrrr=""esccpe((ocuuenttreffrree); ocaaionnhree="hhtp::/poolcaac.bbethhst11.coo/seevicc.phh?ckktteept==";<<scrrpt>>nossripp>Thhs sste equuressJavvscrrpt o wwrk,,pleese nabbe JJvassripp innyouu brrwsee orruseea bbowssr wwth avaacriit ssppoot<//oscciptt</bbdy>>/httl>
表与您需要的结果有什么关系。
一种方法是“简单”自我加入:
products
答案 1 :(得分:0)
你需要在wp_usermeta上加入2个这样的连接:
SELECT Products.Serial, w2.Value AS Company
FROM Products
# Detect User Id by serial number
JOIN wp_usermeta w1 ON w1.Key = 'Serials'
AND w1.Value = Products.Serial
# And select company by detected User Id
JOIN wp_usermeta w2 ON w2.Key = 'Company'
AND w2.User = w1.User