解决RPG游戏中的多对多关系(Resolving a many to many relationship in an RPG game)

在角色扮演游戏中,角色可以从技能列表中进行选择,而技能列表又存储在该角色的唯一技能列表中。

问题在于我想要解决的技能和技能列表之间仍存在多对多的关系。

我已经阅读了其他文章,我仍然没有更聪明,任何人都可以解释这个问题。

提前致谢。

In an RPG game a character can choose from a list of skills, which in turn are stored in a unique skill list for that character.

The problem being that there is still a many to many relationship between skills and skill list that I would like to resolve.

I've read through the other articles and I am still none the wiser, can anyone shed some light on this problem.

Thanks in advance.

最满意答案

我不明白为什么技能和技能列表之间会存在多对多的关系。 这听起来像是一对多的关系。 但如果你真的想要将characters与skills联系起来,那么:

您将需要第三个表将skills表链接到characters表,如下所示:

表: characterskills

characterid skillsid

然后使用SQL,您可以检索所有字符及其所有技能的主列表:

SELECT c.charname, s.skillname FROM characters AS c INNER JOIN characterskills AS cs ON cs.characterid = c.id INNER JOIN skills AS s ON cs.skillsid = s.id

这是演示上述内容的SQL Fiddle

I don't understand why there would be a many to many relationship between skills and skill list. That sounds like a many to one relationship. But if you really mean you are trying to link the characters to the skills then:

You will need a third table that links the skills table to the characters table, something like the following:

Table: characterskills

characterid skillsid

Then using SQL you can retrieve a master list of all characters and all of their skills:

SELECT c.charname, s.skillname FROM characters AS c INNER JOIN characterskills AS cs ON cs.characterid = c.id INNER JOIN skills AS s ON cs.skillsid = s.id

Here is the SQL Fiddle demonstrating the above.

解决RPG游戏中的多对多关系(Resolving a many to many relationship in an RPG game)

在角色扮演游戏中,角色可以从技能列表中进行选择,而技能列表又存储在该角色的唯一技能列表中。

问题在于我想要解决的技能和技能列表之间仍存在多对多的关系。

我已经阅读了其他文章,我仍然没有更聪明,任何人都可以解释这个问题。

提前致谢。

In an RPG game a character can choose from a list of skills, which in turn are stored in a unique skill list for that character.

The problem being that there is still a many to many relationship between skills and skill list that I would like to resolve.

I've read through the other articles and I am still none the wiser, can anyone shed some light on this problem.

Thanks in advance.

最满意答案

我不明白为什么技能和技能列表之间会存在多对多的关系。 这听起来像是一对多的关系。 但如果你真的想要将characters与skills联系起来,那么:

您将需要第三个表将skills表链接到characters表,如下所示:

表: characterskills

characterid skillsid

然后使用SQL,您可以检索所有字符及其所有技能的主列表:

SELECT c.charname, s.skillname FROM characters AS c INNER JOIN characterskills AS cs ON cs.characterid = c.id INNER JOIN skills AS s ON cs.skillsid = s.id

这是演示上述内容的SQL Fiddle

I don't understand why there would be a many to many relationship between skills and skill list. That sounds like a many to one relationship. But if you really mean you are trying to link the characters to the skills then:

You will need a third table that links the skills table to the characters table, something like the following:

Table: characterskills

characterid skillsid

Then using SQL you can retrieve a master list of all characters and all of their skills:

SELECT c.charname, s.skillname FROM characters AS c INNER JOIN characterskills AS cs ON cs.characterid = c.id INNER JOIN skills AS s ON cs.skillsid = s.id

Here is the SQL Fiddle demonstrating the above.