初学者sql问题pt.2错误ora-00933 SQL命令没有正确结束

时间:2011-02-18 15:26:05

标签: sql oracle ora-00933

我必须在DBMS中更新我的表。无法弄清楚为什么我会收到此错误。

  UPDATE Customers
  SET CreditLimit = CreditLimit * 1.25
      FROM(SELECT *
           FROM Orders
           WHERE Amount > 250
           HAVING COUNT(*) >= 2);

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

UPDATE Customers
      SET CreditLimit = CreditLimit * 1.25
          FROM Customers
    Where Id in (
     select CustomerId 
     from orders 
     where  Amount > 250
     Group By CustomerId
     HAVING COUNT(*) >= 2);

UPDATE Customers
      SET CreditLimit = CreditLimit * 1.25
          FROM Customers c
    Where (select count(*) from orders o where o.CustomerId = c.Id And Amount > 250) > =2

答案 1 :(得分:1)

update语句没有像您指定的from子句 你想做这样的事情: 对于拥有至少2笔订单超过250美元的客户,将信用额度提高25%。

update Customers
   set CreditLimit = CreditLimit * 1.25
 where (select count(*)
          from Orders
         where Amount > 250
           and orders.customer_id = Customers.customer_id)) >= 2;

修改
我刚刚注意到你正在使用Oracle(ORA消息)。由于您可能会更新所有客户,我认为最高效的方法是使用“可更新连接”或下面的合并语句:

merge 
 into customers
using (select customer_id
         from Orders o
        where amount > 250
        group 
           by customer_id
       having count(*) >= 2
      ) orders
    on(customers.customer_id = orders.customer_id)
when matched then
   update
      set customers.creditlimit = customers.creditlimit * 1.25;