1

朋友们,我有这些桌子:

Contestant Table:
Winner
Peter

Group Table:
Id Name Score Union
1 Bryan 3 77
2 Mary 1 20
3 Peter 5 77
4 Joseph 2 25
5 John 6 77

我想在小组表上给彼得加 5 分。所以,我想出了这个查询。

UPDATE Group 
SET Score = Score+5
FROM Contestant, Group 
WHERE Contestant.Winner = Group.Name

现在,我还想给与彼得相同的联盟 5 分,即 77 分。

如何将它作为一个查询集成到我现有的查询中?

//更新1

我有与上述类似的问题,但使用 3 个表:

1. Company (table)
CONAME
COPOINTS

2. Group_Member (table)
CONAME
NAME

3. Member (table)
NAME
MPOINTS

我想要一个正确的查询,如下所示,条件如下:

Update Member
Set MPOINTS=MPOINTS+5
Where Company.CONAME=Group_Member.CONAME
And
Group_Member.NAME=Member.NAME

你能更正上面的查询吗?

4

2 回答 2

0
update u set score = score + 5
from contestant c
inner join group g on g.name = c.winner
inner join group u on u.union = g.union

目前尚不清楚,但如果您希望获胜者获得额外的 5 分:

update u set score = (case
  when u.name = c.winner then score + 10
  else then score + 5 end)
from contestant c
inner join group g on g.name = c.winner
inner join group u on u.union = g.union
于 2012-11-11T04:52:57.483 回答
0
UPDATE Group 
SET Score = Score+5
WHERE [Union] = (
    SELECT [Union] 
    FROM Group, Contestant 
    WHERE Group.Name = Contestant.Winner)
于 2012-11-11T04:52:58.340 回答