我已經很久沒有使用 SQL 了,在構建自己的視頻游戲時我不得不重新開始使用它。我正在使用 MySQL,但在這里遇到了一些復雜的問題。
這是我的兩個陣列;
SET @myArrayofRaces = '"Dwarf", "Elf", "Halfling", "Human", "Dragonborn", "Gnome", "Half-Elf", "Half-Orc", "Tiefling"';
SET @myArrayofClasses = '"Barbarian", "Bard", "Cleric", "Druid", "Fighter", "Monk", "Paladin", "Ranger", "Rogue", "Sorcerer", "Warlock", "Wizard"';
正如我們所看到的,我有 9 場比賽和 12 個班級。我想使用這些陣列撰寫 INSERT INTO 陳述句,這樣我就不必手動輸入 108 行。
這是我正在運行的 INSERT INTO 陳述句;
INSERT INTO world_content.character_create_template (
race,
aspect,
instance,
pos_x,
pos_y,
pos_z,
orientation,
faction,
autoAttack,
race_icon,
class_icon,
race_description,
class_description,
isactive,
respawnInstance,
respawnPosX,
respawnPosY,
respawnPosZ,
startingLevel,
sprint
)
VALUES
(
437,
428,
29,
- 170,
74,
154,
0,
1,
- 1,
"Assets/Resources/Assets/Icons/Race Icons/Dwarf.png",
"Assets/Resources/Assets/Icons/Class Icons/Druid.png",
"Dwarf",
"Druid",
1,
29,
- 170,
74,
154,
1,
- 1
)
我需要回圈這個 INSERT INTO 陳述句,直到我完成了所有 108 種種族和類別的組合。因此 Dwarf 將作為每個類出現在資料庫中。然后 Elf 將被插入到每個類的資料庫中。然后是半身人,然后是人類,等等,等等。
Class 陣列只是進入 class_description 和 class_icon 上,您可以看到我正在洗掉指向影像的鏈接。Race 也將遵循race_icon 影像。
有沒有人知道我如何在每場比賽中回圈 ArrayofRaces 12 次,以便我可以輕松匯入課程和比賽?
提前致謝!
uj5u.com熱心網友回復:
您可以使用交叉連接生成所有組合。例如:
INSERT INTO character_create_template (
race,
aspect,
instance,
pos_x,
pos_y,
pos_z,
orientation,
faction,
autoAttack,
race_icon,
class_icon,
race_description,
class_description,
isactive,
respawnInstance,
respawnPosX,
respawnPosY,
respawnPosZ,
startingLevel,
sprint
)
with
race as (
select 'Dwarf' as name
union all select 'Elf' -- repeat this line for more races
),
class as (
select 'Barbarian' as name
union all select 'Bard' -- repeat this line for more classes
)
select
437,
428,
29,
- 170,
74,
154,
0,
1,
- 1,
"Assets/Resources/Assets/Icons/Race Icons/Dwarf.png",
"Assets/Resources/Assets/Icons/Class Icons/Druid.png",
r.name,
c.name,
1,
29,
- 170,
74,
154,
1,
- 1
from race r
cross join class c
請參閱DB Fiddle 上的運行示例。
注意:此示例包括兩個種族和兩個類,以產生總共 4 種組合。添加其余部分,查詢將生成全部 108 個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/393531.html
