Skip to content

Instantly share code, notes, and snippets.

@yucao24hours
Last active December 22, 2015 08:39
Show Gist options
  • Save yucao24hours/6446350 to your computer and use it in GitHub Desktop.
Save yucao24hours/6446350 to your computer and use it in GitHub Desktop.
「勤続年数に応じてボーナスを支給したい。ついては、支払日を2007年度として、入社年度との差で1年毎に1000円上乗せしてくれ」(SQL書き方ドリル 第4章その6 より)
UPDATE
Salary
SET
Amount
= Amount +
(
SELECT
(2007 - e.HireFiscalYear) * 1000
FROM
Employees AS e
WHERE
Salary.EmployeeID = e.EmployeeID
)
WHERE
PayDate = '2008-02-14'
AND
EXISTS
(
SELECT
'X'
FROM
Employees AS e
WHERE
Salary.EmployeeID = e.EmployeeID
)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment