2016-11-29 97 views
0

我有一個查詢在MySQL
Give all managers of First Bank Corporation a 10 percent salary raise unless the salary become greater than $100000; in such cases, give only a 3 percent raise.SQL查詢中的情況?

在我的數據庫我有以下表上,我必須在

  • 員工(EMP_NAME,街道,市)
  • 作品(EMP_NAME工作, COMPANY_NAME,工資)
  • 公司(COMPANY_NAME,市)
  • 管理(EMP_NAME,MANAGER_NAME)`

我也做了查詢的一半的部分,現在我不知道該怎麼辦的其他部分

Update Works 
    set Salary= salary + salary * 0.10 
    where company_name = 'First Bank Corporation' AND 
      emp_name IN (Select manager_name from Manages) AND 
      salary > 100000; 

回答

1
UPDATE ... 
    SET salary = CASE 
        WHEN salary * 1.10 > 100000 
        THEN salary * 1.03 
        ELSE salary * 1.10 
       END 
WHERE ... 

- 或 -

UPDATE ... 
    SET salary = salary * CASE 
          WHEN salary * 1.10 > 100000 
          THEN 1.03 
          ELSE 1.10 
         END 
WHERE ...