我想從表'tourneygamesISF'fiels'op1score'和'op2score'從某個ID更新table'tourneyteamsISF'字段'pointsfavor'和'pointscontra'。使用INNER JOIN的UPDATE表 - 幫助!
例如:
Table name = tourneygamesISF
op1(name of row) vs. op2 - op1score = 25 - op2score = 20
我想更新此:
op1: (from: tourneygamesISF) = ID in tourneyteamsISF
+ pointsfavor = 25 (to: tourneyteamsISF)
+ pointscontra = 20 (to: tourneyteamsISF)
op2: (from: tourneygamesISF) = ID in tourneyteamsISF
+ pointsfavor = 20 (to: tourneyteamsISF)
+ pointscontra = 25 (to: tourneyteamsISF)
我有以下直到現在
UPDATE tourneyteamsISF
INNER JOIN tourneygamesISF g1 ON (tourneyteamsISF.ID = g1.op1)
INNER JOIN tourneygamesISF g2 ON (tourneyteamsISF.ID = g2.op2)
SET pointsfavor = pointsfavor
+ IF(g1.op1score > g1.op2score, g1.op1score - g1.op2score, 0)
+ IF(g2.op2score > g2.op1score, g2.op2score - g2.op1score, 0)
, pointscontra = pointscontra
+ IF(g1.op1score < g1.op2score, g1.op2score - g1.op1score, 0)
+ IF(g2.op2score < g2.op1score, g2.op1score - g2.op2score, 0)
WHERE ID = 1;
但它給人的錯誤:列「ID 'in where clause is ambiguous
個我的表是這樣的:
TABLE tourneyteamsISF
ID integer autoincrement primary key,
name varchar,
pointsfavor integer,
pointscontra integer
TABLE tourneygamesISF
ID integer autoincrement primary key,
op1 integer,
op2 integer,
op1score integer, /*score for team1*/
op2score integer /*score for team2*/
我知道,它必須做一些與命名錶的團隊和遊戲的ID,但我堅持和困惑。我會感激所有我能得到的幫助。
第一all..thnx的....與g1.ID它執行,但它不更新從「pointsfavor」和「pointscontra」' tourneyteamsISF'table ...所以它說受影響的行:0 ....它必須是ID的問題...我如何識別它? – fabio
它仍然說受影響的行0 ...我不知道什麼是問題....幫助PLZ ....插入整數可能出現的問題?或在功能? – fabio