如何更新字段中的最大记录

时间:2015-03-31 19:25:27

标签: ms-access-2007

我的桌子是

sh_name | sh_count |了Shoba
1 | 3 | 1
2 | 7 | 1
3 | 2 | 1
1 | 6 | 2
2 | 5 | 2
3 | 3 | 2

我想在shoba 2中将字段sh_name中的最大记录从3更新为11 我使用此代码但无法正常工作

UPDATE表SET sh_count = 11其中sh_name =(从表格中选择max(sh_name),其中shoba = 2)

1 个答案:

答案 0 :(得分:0)

如果您只想更新一行,则需要重复shoba = 2条件,如下所示:

UPDATE sheet SET sh_count = 11 
WHERE sh_name = (SELECT MAX(sh_name) FROM sheet WHERE shoba = 2)
    AND shoba = 2