2011-02-18 85 views

回答

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