2011-02-18 3 views

답변

1

update 문은 from 조항이 없습니다.
다음과 같이하려고하십니까? 250 개가 넘는 돈을 2 회 이상 주문한 고객의 크레딧 한도가 25 % 증가했습니다.

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

편집
난 그냥 당신이 오라클합니다 (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 
관련 문제