0

我有一个基本上像标题一样的问题,我尝试过的查询是:

INSERT INTO 
  pendingresults, 
  l1_afixtures (pendingresults.TeamAName, pendingresults.TeamA, 
pendingresults.TeamAScore, pendingresults.TeamBScore, pendingresults.TeamB) 
VALUES (
  '$pls', 
  '$TeamA', 
  '$TeamAScore', 
  '$TeamBScore', 
  '$TeamB') 
WHERE 
  l1_afixtures.team_name = $TeamA 
AND  
  l1_afixtures.fixture = $TeamB 
AND 
  l1_afixtures.disabled = 'enabled';

这个查询有什么问题吗,我知道没有

 where l1_afixtures.team_name = $TeamA AND  
 l1_afixtures.fixture = $TeamB AND l1_afixtures.disabled = 'enabled';

工作,但与 where 功能我似乎无法让它工作

有任何想法吗?谢谢

4

2 回答 2

2

你可以这样尝试:

INSERT INTO Table2 (<columns>)
SELECT <columns>
FROM Table1
WHERE <condition>;

在这种特殊情况下,它可能是这样的:

INSERT INTO pendingresults (TeamAName, TeamA, TeamAScore, TeamBScore, TeamB) 
SELECT TeamAName, TeamA, TeamAScore, TeamBScore, TeamB
FROM l1_afixtures
WHERE 
    l1_afixtures.team_name = $TeamA 
    AND l1_afixtures.fixture = $TeamB 
    AND l1_afixtures.disabled = 'enabled'
于 2012-09-02T16:18:20.317 回答
-2

你不能做一个INSERT ... VALUES... WHERE

你可以做一个INSERT .... SELECT ... WHERE

而且您一次只能INSERT进入一张桌子。

所以

insert into pendingresults (TeamAName, TeamA, TeamAScore, TeamBScore, TeamB) 
values('$pls', '$TeamA', '$TeamAScore', '$TeamBScore', '$TeamB') 

或者

insert into pendingresults (TeamAName, TeamA, TeamAScore, TeamBScore, TeamB) 
Select TeamAName, TeamA, TeamAScore, TeamBScore, TeamB
from l1_afixtures
where 
    l1_afixtures.team_name = $TeamA 
    AND l1_afixtures.fixture = $TeamB 
    AND l1_afixtures.disabled = 'enabled'
于 2012-09-02T16:11:17.050 回答