You are on page 1of 2

Problem:

You probably already know that you pay 7.65% of your income in “FICA” taxes: 6.2%
Social Security tax (up to some maximum amount) and 1.45% Medicare tax. What you
might not know is that your employer pays these same amounts as well, so if you are
self-employed (i.e., an independent contractor) rather than working for a company,
then you have to pay that other 7.65% too – for a total of 15.3%. This is called
“Self-employment tax”.

Suppose you are an independent database consultant and you are paid a high hourly
rate for your expertise. Let’s figure out your total Self-employment tax for a
collection of years. Consider the tables INCOME and RATES, constructed by the
following script:

DROP TABLE INCOME CASCADE CONSTRAINTS;


CREATE TABLE INCOME (Year NUMBER(4) PRIMARY KEY, Hours NUMBER(4,0), Rate
NUMBER(5,2));
INSERT INTO INCOME VALUES (2017, 119, 250);
INSERT INTO INCOME VALUES (2018, 205, 250);
INSERT INTO INCOME VALUES (2019, 385, 300);
INSERT INTO INCOME VALUES (2020, 330, 300);
INSERT INTO INCOME VALUES (2021, 412, 350);
INSERT INTO INCOME VALUES (2022, 28, 350);
SELECT Year, Hours, to_char(Rate,'999.99') as Rate FROM INCOME;
-- to_char formats the output to a fixed width and number of decimal places
DROP TABLE RATES CASCADE CONSTRAINTS;
CREATE TABLE RATES (SSRate NUMBER(4,3), MedRate NUMBER(4,3), MaxSS NUMBER(7,2));
INSERT INTO RATES VALUES (0.124, 0.029, 12600.00);
SELECT * FROM RATES;
COMMIT;

Write a script file Assignment6.sql containing just an anonymous PL/SQL block that
will do the following:

First, read the Social Security tax rate SSRate, Medicare tax rate MedRate, and
maximum Social Security tax MaxSS from the RATES table, store them in variables,
and output their values. (You may assume that the RATES table contains exactly one
record.)

Next, for each row in the INCOME table, read the year, hours worked, and hourly
rate, and compute your earnings for that year (hours worked times hourly rate).
From your earnings, compute the Self-employment tax for that year, which will have
two components:

• Social Security tax, which is


o (SSRate * earnings), if (SSRate * earnings) is less than or equal to MaxSS;
o MaxSS, if (SSRate * earnings) is greater than MaxSS.
• Medicare tax, which is always (MedRate * earnings).

The Self-employment tax is the sum of the Social Security tax and the Medicare tax.

Output each year’s information on a single line, displaying the year, your earnings
for the year, the Social Security and Medicare tax amounts, and the Self-employment
tax. (If you want to format the output nicely to line up the decimal points and
display exactly two digits to the right of each decimal point, use the to_char
function with format strings of appropriate lengths – but doing that is optional.)
Add the word ‘MAXSS’ to the end of each line in which the Social Security tax is
the maximum amount MaxSS.
Finally, compute the total Self-employment tax paid over all years in the INCOME
table, and output that value at the end. For the sample data given, the output
should be something like this (including the optional formatting):

Rates and maximum SS tax: .124 .029 12600

2017 29750.00 3689.00 862.75 4551.75


2018 51250.00 6355.00 1486.25 7841.25
2019 115500.00 12600.00 3349.50 15949.50 MAXSS
2020 99000.00 12276.00 2871.00 15147.00
2021 144200.00 12600.00 4181.80 16781.80 MAXSS
2022 9800.00 1215.20 284.20 1499.40

Total Self-employment tax: 61770.70

(Of course, this is just an example – your anonymous PL/SQL procedure should work
in general, not just for the given sample data.)

Remarks:

1. You may copy and paste the script I supplied into SQLDeveloper to set up the
tables so that you can test your code, but your submitted solution should include
only the code you have written to solve the problem – not any of my code. Be sure
that your submitted script file is in a plain text format that can be run and
tested in SQLDeveloper.

You might also like