0

我有一张桌子

NAME   |   BONUS  
----------------
anil   |   40  
suresh |   25  
ramesh |   44  
anil   |   35  
anil   |   15

我想删除具有name = anil and bonus < max bonus of anil OUTPUT

anil   | 40
suresh | 25
ramesh | 44

我试过查询:

delete from table where name like 'anil' and bonus < (select max(bonus) 
from table where name like 'anil';

但它给出了一个语法错误。任何人都可以帮忙。我会很感激的。

4

3 回答 3

0

您缺少子查询的结尾括号:

delete from table
where
  name like 'anil' and
  bonus < (select max(bonus) from table where name like 'anil'

应该

delete from table
where
  name like 'anil' and
  bonus < (select max(bonus) from table where name like 'anil')
于 2013-04-24T12:31:14.137 回答
0

您需要将 Group by 与聚合函数一起使用。

检查以下查询是否相同。

delete from table where bonus < (select max(bonus) from table where name like 'anil' Group By name)
于 2013-04-24T12:31:57.263 回答
0

“表”一词是保留的 SQL 关键字,我认为您的错误指的是

您不能在 FROM 子句中指定目标表“表”进行更新

于 2013-04-24T12:48:58.870 回答