I would expect something like this:
INSERT INTO PensionFunds (EmployeeId, Amount, PensionProvider)
SELECT EmployeeId, Salary * 0.05, PensionId
FROM CompanyEmployees;
This does not take a zillion things into account, such as:
- Not all rows in
CompanyEmployees
might be active employees. - Not all rows in
CompanyEmployees
might be contributing to the pension fund. - There could perhaps be duplicates in
CompanyEmployees
(what if someone has two part-time positions). - You don’t seem to have a date, so you are allowing multiple contributions at the same time.
- Perhaps not all employees contribute 5%.
1
solved A SQL Server query that increases the value of everyone’s pension fund by one month’s worth of contributions