Interpret this SQL in to English : <p>I've been given the task of rewriting certain sections of this SQL but am having trouble interpreting it completely. In plain English could an SQL master explain what is happening from "appointments_2015 AS" to the end. </p>

<pre><code>CREATE TABLE appointment (
emp_id integer NOT NULL,
jobtitle varchar(128) NOT NULL,
salary decimal(10,2) NOT NULL,
start_date date NOT NULL,
end_date date NULL
);

ALTER TABLE appointment ADD CONSTRAINT pkey_appointment PRIMARY KEY 
(emp_id, jobtitle, start_date);
ALTER TABLE appointment ADD CONSTRAINT chk_appointment_period CHECK 
(start_date &lt;= end_date);


WITH current_employees AS (
SELECT DISTINCT emp_id
FROM appointment
WHERE end_date IS NULL
),
appointments_2015 AS (
SELECT a.emp_id, salary,
CASE WHEN start_date &lt; ’2015-01-01’ THEN ’2015-01-01’ ELSE start_date END 
AS start_date,
CASE WHEN end_date &lt; ’2016-01-01’ THEN end_date ELSE ’2015-12-31’ END AS 
end_date
FROM appointment a
JOIN current_employees ce ON a.emp_id = ce.emp_id
WHERE start_date &lt; ’2016-01-01’ AND (end_date &gt;= ’2015-01-01’ OR end_date 
IS NULL)
)
SELECT 
  emp_id,
  SUM( salary * (end_date - start_date + 1) / 365 ) AS total
FROM appointments_2015
GROUP BY emp_id
</code></pre>
