gpt4 book ai didi

php连接3个表然后插入到第4个表

转载 作者:行者123 更新时间:2023-11-29 21:32:46 24 4
gpt4 key购买 nike

这里是连接:

SELECT 
gc3025_raid_results.raid_id,
gc3025_game_units.planet_id,
gc3025_game_units.g_dist,
gc3025_game_units.unit_name,
gc3025_units_base.unit_type,
gc3025_game_units.code,
gc3025_game_units.cdamage,
gc3025_units_base.defense_raid_score,
gc3025_units_base.raid_damage
FROM gc3025_game_units
JOIN gc3025_units_base
ON gc3025_game_units.code = gc3025_units_base.unit_code
JOIN gc3025_raid_results
ON gc3025_raid_results.district_idg = gc3025_game_units.g_dist

然后我需要插入另一个表

INSERT INTO gc3025_raid_defenders( 
raid_ids, planet_id, district_id,
unit_name, unit_type, unit_code,
raid_score, raid_damage)
SELECT ... (see above) ...

如有任何建议,我们将不胜感激。

最佳答案

这应该可以帮助您继续操作,但您需要添加其他字段。确保 insert() 中字段的名称和顺序与 select() 中的字段匹配

insert into gc3025_raid_defenders (raid_ids, planet_id, etc...)
select (gc3025_raid_results.raid_id, gc3025_game_units.planet_id, etc...)
from gc3025_game_units gu
join gc3025_units_base ub
on gu.code = ub.unit_code
join gc3025_raid_results rr
on gu.g_dist = rr. district_idg

顺便说一句,如果可能的话,请考虑在表之间一致地命名字段,例如 g_dist。

关于php连接3个表然后插入到第4个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35135502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com