Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のように、データベースに2つのテーブルがあります。
Instructor (id, name, department_id, salary) Department (department_id, dep_name, location)
特定の部門のインストラクターのセットの給与を増やしたいとします。たとえば、物理学部門 (部門 ID = 1 など) のすべてのインストラクターの給与を 10% 増やしたいとします。SQLクエリを使用してそれを行うにはどうすればよいですか?
10% 増加するということは、 を掛けることを意味する1.1ため、必要なことは単純な更新だけです。
1.1
UPDATE Instructor SET salary = salary * 1.1 WHERE department_id=1
salary * 10 / 100長い説明: 10% は、またはを意味することを思い出してsalary/10ください。展開すると 、または10 進数表記になりますsalary + salary/10。salary * (1 + 1/10)salary * 1.1
salary * 10 / 100
salary/10
salary + salary/10
salary * (1 + 1/10)
salary * 1.1