2

我有一个使用以下 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

3 回答 3

1

在 T-SQL(MS-SQL Server 方言)中,这将是

Update Member
   set MPOINTS = MPOINTS + 5
  from Group_Member 
       join Company on Company.CONAME = Group_Member.CONAME
 where Group_Member.NAME = Member.NAME

我想提醒您,名称对于主键和外键关系都不是一个好的选择。如果不违反主键约束,您将永远无法更改名称。请改用(数字、自动增量)ID 列。

于 2012-11-12T07:38:34.390 回答
0

尝试这个:

Update M
Set    MPOINTS=MPOINTS+5
from   Member M 
join   Group_Member GM
on     GM.NAME=M.NAME
join   Company C
on     C.CONAME=GM.CONAME
于 2012-11-12T07:38:37.137 回答
0

SQL Server 2005+

UPDATE x
SET x.MPOINTS += 5
FROM (SELECT m.MPOINTS FROM Company c JOIN Group_Member g ON c.CONAME = g.CONAME
                                      JOIN Member m ON g.NAME = m.NAME) x
于 2012-11-12T07:44:12.230 回答