我的JOIN操作中是否存在语法错误的快速修复

时间:2019-05-12 10:34:28

标签: sql ms-access

我对sql还是很陌生,可能对此感到不安,但是我在join语句中一直遇到语法错误。

我正在尝试获取单个角色的特定统计信息。我添加了更多括号以消除丢失的运算符错误,并且我尝试仅在相同表的内部联接周围添加括号。到目前为止,join语句是唯一引发错误的事情。

SELECT CHARACTER.CharacterName, CHARACTER.Alignment, INVENTORY.Equipped, 
ITEMS.ItemName,
ITEMS.PhysDef, ITEMS.MDef, ITEMS.Dodge, ITEMS.Damage, ITEMS.CritMultiplier, 
ITEMS.Range,
ITEMS.AttackSpeed, JOB_CHARACTER.JobLevel, RACE_CHARACTER.RacialLevel, 
RACE.RaceName, RACE.Strength,
RACE.Skill, RACE.Vitality, RACE.Arcane, RACE.Spirit, RACE.Charisma, 
RACE.Luck, JOB.JobName,
JOB.HP, JOB.AttackBonus, JOB.Agility, JOB.Might, JOB.SpellPower, JOB.Vital, 
JOB.Nimble, JOB.Mental,
JOB.Curese, JOB.SpellCasting, JOB.ManaBase, JOB.ManaType, JOB.Ki, 
SKILLS.Alchemy, SKILLS.Awareness,
SKILLS.Climb, SKILLS.Coach, SKILLS.Construction, SKILLS.Decieve, 
SKILLS.DisarmMechanism,
SKILLS.DiscernTruth, SKILLS.Dishearten, SKILLS.Fly, SKILLS.Forge, 
SKILLS.Gymnastics,SKILLS.Identify,
SKILLS.Leadership, SKILLS.Lore_9Realms, SKILLS.Lore_Alternative, 
SKILLS.Lore_Arcane,
SKILLS.Lore_Arithmancy, SKILLS.Lore_Divine, SKILLS.Lore_Geography, 
SKILLS.Lore_Nature,
SKILLS.Lore_Nobility, SKILLS.Lore_Religion, SKILLS.Lore_Spiritual, 
SKILLS.Medical, 
SKILLS.Performance, SKILLS.Ride, SKILLS.Steal, SKILLS.Stealth, 
SKILLS.Subterfuge,
SKILLS.Swim, SKILLS.Tailor, SKILLS.UseContraption, SKILLS.Wilderness

FROM (((((((CHARACTER INNER JOIN RACE_CHARACTER ON 
CHARACTER.CharacterID=RACE_CHARACTER.CharacterID)
LEFT JOIN JOB_CHARACTER ON CHARACTER.CharacterID=JOB_CHARACTER.CharacterID)
LEFT JOIN INVENTORY ON CHARACTER.CharacterID=INVENTORY.CharacterID)
INNER JOIN INVENTORY ON ITEMS.ItemID =INVENTORY.ItemID)
INNER JOIN JOB ON JOB.JobID=JOB_CHARACTER.JobID)
LEFT JOIN SKILLS ON JOB.JobID=SKILLS.JobID)
INNER JOIN RACE ON RACE.RaceID=RACE_CHARACTER.RaceID)

WHERE  ((CHARACTER.CharacterID)=1) AND ((JOB.JobID)=3) AND 
((RACE.RaceID)=6);

我希望它能输出该单个角色,其名称和技能的统计信息,但是目前未输出任何信息。

1 个答案:

答案 0 :(得分:0)

您的select语句从ITEMS表中获取8个字段:

SELECT 
    ...
    ITEMS.ItemName,
    ITEMS.PhysDef, 
    ITEMS.MDef,
    ITEMS.Dodge,
    ITEMS.Damage, 
    ITEMS.CritMultiplier, 
    ITEMS.Range,
    ITEMS.AttackSpeed,
    ...

但是,ITEMS子句引用的是表{

from

我应该想象SQL代码应该更改为:

FROM 
    (
        (
            (
                (
                    (
                        (
                            (
                                CHARACTER INNER JOIN RACE_CHARACTER ON 
                                CHARACTER.CharacterID=RACE_CHARACTER.CharacterID
                            )
                            LEFT JOIN JOB_CHARACTER ON 
                            CHARACTER.CharacterID=JOB_CHARACTER.CharacterID
                        )
                        LEFT JOIN INVENTORY ON 
                        CHARACTER.CharacterID=INVENTORY.CharacterID
                    )
                    INNER JOIN INVENTORY ON ----------< INVENTORY table referenced twice
                    ITEMS.ItemID =INVENTORY.ItemID
                )
                INNER JOIN JOB ON 
                JOB.JobID=JOB_CHARACTER.JobID
            )
            LEFT JOIN SKILLS ON 
            JOB.JobID=SKILLS.JobID
        )
        INNER JOIN RACE ON 
        RACE.RaceID=RACE_CHARACTER.RaceID
    )

请注意,我已将几个SELECT CHARACTER.CharacterName, CHARACTER.Alignment, INVENTORY.Equipped, ITEMS.ItemName, ITEMS.PhysDef, ITEMS.MDef, ITEMS.Dodge, ITEMS.Damage, ITEMS.CritMultiplier, ITEMS.Range, ITEMS.AttackSpeed, JOB_CHARACTER.JobLevel, RACE_CHARACTER.RacialLevel, RACE.RaceName, RACE.Strength, RACE.Skill, RACE.Vitality, RACE.Arcane, RACE.Spirit, RACE.Charisma, RACE.Luck, JOB.JobName, JOB.HP, JOB.AttackBonus, JOB.Agility, JOB.Might, JOB.SpellPower, JOB.Vital, JOB.Nimble, JOB.Mental, JOB.Curese, JOB.SpellCasting, JOB.ManaBase, JOB.ManaType, JOB.Ki, SKILLS.Alchemy, SKILLS.Awareness, SKILLS.Climb, SKILLS.Coach, SKILLS.Construction, SKILLS.Decieve, SKILLS.DisarmMechanism, SKILLS.DiscernTruth, SKILLS.Dishearten, SKILLS.Fly, SKILLS.Forge, SKILLS.Gymnastics, SKILLS.Identify, SKILLS.Leadership, SKILLS.Lore_9Realms, SKILLS.Lore_Alternative, SKILLS.Lore_Arcane, SKILLS.Lore_Arithmancy, SKILLS.Lore_Divine, SKILLS.Lore_Geography, SKILLS.Lore_Nature, SKILLS.Lore_Nobility, SKILLS.Lore_Religion, SKILLS.Lore_Spiritual, SKILLS.Medical, SKILLS.Performance, SKILLS.Ride, SKILLS.Steal, SKILLS.Stealth, SKILLS.Subterfuge, SKILLS.Swim, SKILLS.Tailor, SKILLS.UseContraption, SKILLS.Wilderness FROM ( ( ( ( ( ( ( CHARACTER INNER JOIN RACE_CHARACTER ON CHARACTER.CharacterID=RACE_CHARACTER.CharacterID ) LEFT JOIN JOB_CHARACTER ON CHARACTER.CharacterID=JOB_CHARACTER.CharacterID ) LEFT JOIN INVENTORY ON CHARACTER.CharacterID=INVENTORY.CharacterID ) LEFT JOIN ITEMS ON ITEMS.ItemID =INVENTORY.ItemID ) LEFT JOIN JOB ON JOB.JobID=JOB_CHARACTER.JobID ) LEFT JOIN SKILLS ON JOB.JobID=SKILLS.JobID ) INNER JOIN RACE ON RACE.RaceID=RACE_CHARACTER.RaceID ) WHERE CHARACTER.CharacterID = 1 AND JOB.JobID = 3 AND RACE.RaceID = 6 更改为inner joins,因为如果您在left joins右边的表上使用inner join(或left join的左侧),那么您将收到模糊的外部联接错误。