0

我在两个表中有数据:

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;
4

2 回答 2

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;
于 2013-05-18T02:10:46.090 回答
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);

我增加了价值。查看在mysql中将数据从一个表插入另一个表

于 2013-05-18T02:03:27.847 回答