我有两个表中的数据:
tbl_games
包含以下列:
game_id, season, date, home_team, visiting_team,
home_score, visiting score, home_score_half_time, visiting score_half_time
tbl_formation
包含以下列:
game_id, home_formation, home_team, visiting_team, visiting_formation
我想将这些表中的数据附加到具有以下列的game_team
表中:
game_id, team_id, status, end_score, half_score, Formation
而不是将home_team
visiting_team
分开,我希望将它们全部置于team_id
之下,状态表明它是主队还是特定比赛的客队。
我正在尝试下面的查询,但它不起作用
INSERT INTO Game_Team ( game_id, Team_ID, End_Score, half_score, Formation )
SELECT G.game_id, G.home_team, G.home_score_half_time, G.home_score, GL.home_formation
FROM tbl_games AS G
INNER JOIN tbl_formation AS GL ON G.game_id = GL.game_id;
答案 0 :(得分:0)
INSERT INTO Game_Team ( game_id, Team_ID, End_Score, half_score, Formation )
values(SELECT G.game_id, G.home_team, G.home_score_half_time, G.home_score, GL.home_formation
FROM tbl_games AS G
INNER JOIN tbl_formation AS GL ON G.game_id = GL.game_id);
答案 1 :(得分:0)
试试这个
INSERT INTO Game_Team ( game_id, Team_ID, End_Score, half_score, Formation )
SELECT G.game_id, G.home_team & ' ' & G.visiting_team, G.home_score_half_time, G.home_score, GL.home_formation
FROM tbl_games AS G
INNER JOIN tbl_formation AS GL ON G.game_id = GL.game_id;