mysql-insert上相关表的值?

3yhwsihp  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(301)

这种说法适用于:

UPDATE 
    registrations 
    JOIN players ON registrations.aa_player_id = players.a_player_id 
SET 
    registrations.`Player First`=players.player_first,    
    registrations.`Player Last`=players.player_last,    
    registrations.`Player Gender`=players.gender,
    players.date_of_birth=registrations.player_dob ;

每当向表registrations添加新行时,我想设置一个触发器来执行相同的操作(仅针对一行)
我试过这个密码
创建触发器 lookup_player 插入之前 registrations 每行更新注册
设置
新的。 Player Last =players.player\u最后,
新的。 Player First =players.player\u first,new.registrations。 Player Gender =玩家性别,
new.player\u dob=players.date\u出生日期
其中new.aa\u player\u id=players.a\u player\u id;
但我在注册中添加新行时出错
1054-“where子句”中的未知列“players.a\u player\u id”
但这个专栏确实存在

yyyllmsg

yyyllmsg1#

我想出来了

CREATE  TRIGGER `lookup player`

插入之前 registrations 每行
设置
新的。 Player Last =(从players where new.aa\u player\u id=players.a\u player\u id中选择players.player\u last),
新的。 Player First =(首先从players where new.aa\u player\u id=players.a\u player\u id中选择players.player\u),
新的。 Player Gender =(从players where new.aa\u player\u id=players.a\u player\u id中选择players.gender),
new.player\u dob=(从players where new.aa\u player\u id=players.a\u player\u id中选择players.date\u of\u birth);

相关问题