讓說我有一個名爲表:條件單個SQL查詢插入
EMP(Eid,Ename,ESalary)
現在我要編寫一個查詢,將更新:
if employee's salary >= 20000 then increment 25% else update 15% salary
讓說我有一個名爲表:條件單個SQL查詢插入
EMP(Eid,Ename,ESalary)
現在我要編寫一個查詢,將更新:
if employee's salary >= 20000 then increment 25% else update 15% salary
update EMP
set ESalary = CASE WHEN salary >= 20000
THEN salary * 1.25
ELSE salary * 1.15
END;
試試這個:
update emp a set esalrary =
(select (case when esalary >=20000 then esalary+(esalary*25/100)
else esalary+(esalary*25/100) end) from emp b where a.eid=b.eid);
非常感謝你 – 2013-04-25 08:44:34
Thanks Mate。我忘記了案件 – 2013-04-25 08:43:24