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
长解释:回想一下 10% 表示salary * 10 / 100,或salary/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