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

编程入门 行业动态 更新时间:2024-10-21 23:02:34
解决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.

更多推荐

本文发布于:2023-08-07 19:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465562.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关系   游戏中   RPG   game   relationship

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!