我需要为侦察数据库编写一个查询,该数据库将徽章的要求与给定成员已经获得的技能进行比较。目的是多种技能适用于多个徽章。我的相关表格(有很多)看起来像这样:
Badge_Table : Badge_ID , BADGE_NAME, Badge_Description,
Badge_Skills_Table : Badge_Skill_ID , Badge_ID, skill_id也,
Skills_Table : skill_id也, 技能名称, skill_description的,
Skills_Earned_Table : Skills_Earned_ID skill_id也 USER_ID
USER_TABLE : USER_ID , 名称, 年龄, 地址
主键以斜体显示,外键关系从Badge_table到Badge_Skills_Table到Skills_Table到Skills_Earned_table到User_Table。
到目前为止,我提出了以下想法:
SELECT badge_table.badge_name
FROM (badge_table
INNER JOIN badge_skills_table ON badge_ID
INNER JOIN Skills_Table ON skill_Id)
WHERE Skills_Table.Skill_Id = 1;
SELECT badge_table.badge_name
FROM (badge_table
INNER JOIN badge_skills_table ON badge_ID
INNER JOIN Skills_Table ON skill_Id)
WHERE Skills_Table.Skill_Id = Skill_Badge_Table.Skill_Id
SELECT badge_table.badge_name
FROM (badge_table
INNER JOIN badge_skills_table ON badge_ID
INNER JOIN Skills_Table ON skill_Id
INNER JOIN Skills_Earned_Table On skill_ID
INNER JOIN users_table ON user_ID)
WHERE Skills_Earned_Table.User_ID= 1 AND Skills_Earned_Table.SKILL_ID = Skill_Badge_Table.skill_ID
所以任何人都可以帮助指导我:
我很感激您提供的任何帮助,
答案 0 :(得分:1)
您的<conditions>
条款中没有ON
。请尝试我的查询:
SELECT A.badge_name
FROM badge_table A
INNER JOIN badge_skills_table B ON A.badge_ID=B.badge_ID
INNER JOIN Skills_Table C ON B.skill_Id=C.skill_ID
INNER JOIN Skills_Earned_Table D ON C.skill_ID=D.skill_ID
INNER JOIN users_table E ON user_ID ON D.user_ID=E.user_ID
WHERE D.User_ID= 1 AND D.skill_ID = B.skill_ID