传递select的结果以删除查询

时间:2013-04-24 12:26:10

标签: asp.net

我有一张桌子

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';

但它给出了语法错误。 谁能帮忙。我会感恩的。

3 个答案:

答案 0 :(得分: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')

答案 1 :(得分:0)

您需要使用具有聚合函数的Group by。

检查以下查询是否相同。

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

答案 2 :(得分:0)

“table”这个词是一个保留的SQL关键字,我认为你的错误指的是

  

您无法在FROM子句

中为更新指定目标表'table'