您好我不知道如何将它放在一个简短的句子中,但我有DB表,如下所示
用户表
项目
Item_Equipped
我想生成一个将显示如下格式的查询
user_id |头| head_item_name |手| hand_item_name | ...
到目前为止我只能做到这一点:
SELECT user.user_id, user.username,
equipments.head, equipments.head_acc,
equipments.hand,
equipments.acc, equipments.body
FROM gw_member_equipped AS equipments
LEFT JOIN gw_member AS user ON user.memberid = equipments.member_id
哪个(我必须诚实地说)不做任何事情。
我尝试在item和item_equipped之间执行INNER JOIN但是我无法获取每个项目的个人名称(基于其项目ID)
答案 0 :(得分:0)
您需要使用ITEM_EQUIPPED表加入ITEM表两次。
您可以使用以下查询查询所需的输出列。
SELECT USER.User_Id,
Item_Equipped.Head,
Item_Heads.Item_Id Head_Item_Id, -- if you want you can remove this column
Item_Heads.Item_Name Head_Item_Name,
Item_Equipped.Hand,
Item_Hands.Item_Id Hand_Item_Id, -- and this column also as these columns are same as their previous select columns
Item_Hands.Item_Name Hand_Item_Name
FROM USER, Item Item_Heads, Item Item_Hands, Item_Equipped
WHERE USER.User_Id = Item_Equipped.User_Id
AND Item_Heads.Item_Id = Item_Equipped.Head
AND Item_Hands.Item_Id = Item_Equipped.Hand