1

我正在为一个小型游戏开发数据库结构,该游戏使用“套件”作为盔甲套装。目前我有 4 张桌子:“kit”、“kit_armor”、“kit_item”和“kit_item_enchantment”。“kit”表保存工具包的 id 和名称,“kit_armor”表保存工具包的盔甲,“kit_item”表保存“kit_armor”列可以指向的项目,“kit_item_enchantment”表保存特定物品的附加附魔数据。

现在我一直在尝试查询以及搜索堆栈溢出和互联网重置以编写一个查询,该查询将从数据库中获取所有套件信息,但遗憾的是没有任何结果。

这是表结构:

mysql> describe kit;
+----------+-----------------+------+-----+---------+----------------+
| Field    | Type            | Null | Key | Default | Extra          |
+----------+-----------------+------+-----+---------+----------------+
| kit_id   | int(4) unsigned | NO   | PRI | NULL    | auto_increment |
| kit_name | varchar(32)     | NO   | UNI | NULL    |                |
+----------+-----------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)

mysql> describe kit_armor;
+------------+-----------------+------+-----+---------+-------+
| Field      | Type            | Null | Key | Default | Extra |
+------------+-----------------+------+-----+---------+-------+
| kit_id     | int(4) unsigned | NO   | PRI | NULL    |       |
| helmet     | int(4) unsigned | YES  | MUL | NULL    |       |
| chestplate | int(4) unsigned | YES  | MUL | NULL    |       |
| leggings   | int(4) unsigned | YES  | MUL | NULL    |       |
| boots      | int(4) unsigned | YES  | MUL | NULL    |       |
+------------+-----------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

mysql> describe kit_item;
+------------+-----------------+------+-----+---------+----------------+
| Field      | Type            | Null | Key | Default | Extra          |
+------------+-----------------+------+-----+---------+----------------+
| id         | int(4) unsigned | NO   | PRI | NULL    | auto_increment |
| item_id    | int(4) unsigned | NO   |     | NULL    |                |
| stack_size | int(4) unsigned | NO   |     | NULL    |                |
+------------+-----------------+------+-----+---------+----------------+
3 rows in set (0.01 sec)

mysql> describe kit_item_enchantment;
+----------------+-----------------+------+-----+---------+-------+
| Field          | Type            | Null | Key | Default | Extra |
+----------------+-----------------+------+-----+---------+-------+
| item_id        | int(4) unsigned | NO   | PRI | NULL    |       |
| enchantment_id | int(4) unsigned | NO   |     | NULL    |       |
| tier           | int(4) unsigned | NO   |     | NULL    |       |
+----------------+-----------------+------+-----+---------+-------+
3 rows in set (0.01 sec)

和引用的列:

+---------------------------+--------------------+-------------------------------+-----------------
| TABLE_NAME                | COLUMN_NAME        | REFERENCED_TABLE_NAME | REFERENCED_COLUMN_NAME |
+---------------------------+--------------------+-------------------------------+-----------------
| kit_armor                 | kit_id             | kit                   | kit_id                 |
| kit_armor                 | helmet             | kit_item              | id                     |
| kit_armor                 | chestplate         | kit_item              | id                     |
| kit_armor                 | leggings           | kit_item              | id                     |
| kit_armor                 | boots              | kit_item              | id                     |
| kit_item_enchantment      | item_id            | kit_item              | id                     |

我的问题是获取所有套件信息的最佳方法是什么,以及是否可以在单个查询(JOIN?)中这样做,还是我必须将其拆分为多个查询?

这对我有很大帮助,从昨天开始我一直在努力解决这个问题,同时我对从数据库中选择关系数据的最佳方法进行了大量研究,我只遇到了非常复杂的指南和查询令人难以置信的混乱。

提前致谢,

乔纳斯

4

0 回答 0