2012-04-06 50 views
0

我有兩個表,一個包含團隊列表,另一個包含這些團隊的計劃列表和得分結果。我希望在向排定表格中插入一行時能夠更新小組表格。因此,例如,如果我有:有關兩個表與功能的Mysql

Teams table 

Team1 
Team2 

Schedules table 

team1, 3 
team2, 1 

什麼,我希望能夠做的就是當比分字段更新我需要更新球隊表不同的領域。所以,當我更新此時間表排,

它會插入3成排的TEAM1之一,1爲TEAM2

此外,我想能夠計算的分數之間的差異,還插入這成隊表。

什麼是最好的實施方式?

我需要一個函數才能比較分數嗎?

謝謝,

到目前爲止,我想到做這樣的事情。

update table teams set teams.gamesplayed = teams.gameplayed +1 /*this would add one to the games played field because they just played.*/ 

然後爲進球像

update teams set teams.gf = 
(

select t.goalsscored 
from schedule t, teams s 
where t.teamname = s.team1name AND) 

) 
+5

那麼,你到目前爲止有什麼? – Norse 2012-04-06 05:31:19

回答

1

你需要加上更新和INSERT觸發器隊表 - 多數民衆贊成。 觸發器,你可以做任何你需要的。當然,您可以創建獨立功能並從觸發器中調用它。

+0

我不允許在godaddy帳戶上創建觸發器:( – user541597 2012-04-07 21:02:01