我在这个问题上摸不着头脑。
我必须更新数据库表中所有在该数据库表中有多个条目的用户的得分字段...但是如果下面满足其中一个参数/约束,它只会更新得分字段。
例如,表格中有2个(对于每个用户)两个守门员,但只会更新其中一个。以下工作,但只有当有一个用户...所以数据库表中只有2行为2个守门员。
$result = mysqli_query($db,"UPDATE Points
SET Points.Score=(SELECT Week_22.TP FROM Week_22 WHERE
Week_22.Player=Points.Player)
WHERE Position='Goalkeeper' AND Active='yes' AND Played='yes'
OR Position='Goalkeeper' AND Active='no' AND Played='yes'
OR Position='Goalkeeper' AND Active='no' AND Played='no'
LIMIT 1
");
我认为GROUP BY可能有效,但没有运气。因此,我无法思考如何将上述内容扩展为适用于表格中的每个字段和用户。
任何帮助都将不胜感激。
答案 0 :(得分:0)
您需要在WHERE子句中添加括号以分隔3个主要的“OR”逻辑语句
$result = mysqli_query($db,"UPDATE Points
SET Points.Score=(SELECT Week_22.TP FROM Week_22 WHERE
Week_22.Player=Points.Player)
WHERE (Position='Goalkeeper' AND Active='yes' AND Played='yes')
OR (Position='Goalkeeper' AND Active='no' AND Played='yes')
OR (Position='Goalkeeper' AND Active='no' AND Played='no')
");