Академический Документы
Профессиональный Документы
Культура Документы
The following description may not be 100% perfect - but feel free to message me for
clarification or questions.
THE JOB
========
I would like you to extend the script in Appendix 2 so that the output contains 2
additional columns: CHECKUP and EVALUATIONCOUNT
1) Each row must have a calculated CHECKUP column showing the status of the
EVALUATION
2) Each row must have a calculated count of how many EVALUATIONS there are, for
that ENGAGEMENT in total
The CHECKUP column for each ENGAGEMENT, can have one of 3 possible values...
"Neglected", "In Progress", or "Completed".
For CHECKUP to be "Completed": The ENGAGEMENT's LAST report must be
REPORTTYPE="Final"
For CHECKUP to be "InProcess": The ENGAGEMENT's LAST report REPORTDATE must be less
than 2 x REPORTFREQUENCY
For CHECKUP to be "Neglected": The ENGAGEMENTs LAST ENGAGEMENT's report's
REPORTDATE must be older than 2 x REPORTFREQUENCY
CREATE TABLE "engagements" ("id" integer not null primary key autoincrement,
"EngagementTitle" varchar null, "EvaluationFrequency" varchar null);
CREATE TABLE "evaluations" ("id" integer not null primary key autoincrement,
"engagement_id" integer not null, "EvaluationPeriod" varchar null, "EvaluationType"
varchar null, foreign key("engagement_id") references "engagements"("id"));
COMMIT;
SELECT t.engagementTitle,
t.EvaluationFrequency,
t1.EvaluationType AS LastEvaluationType,
t1.EvaluationPeriod as LastEvaluationPeriod,
"***" AS Checkup,
"***" AS EvaluationCount
FROM engagements as t INNER JOIN
(
SELECT *, (SELECT COUNT(*) FROM evaluations tt WHERE
tt.engagement_id = t1.engagement_ID and tt.evaluationperiod>=t1.evaluationperiod)
rn
FROM evaluations t1
)
AS t1 ON t1.engagement_id = t.id and rn = 1
ORDER BY t1.EvaluationPeriod;
TESTS
======================================================
Here is how I will test the result set:
1. Each ENGAGEMENT only occurs once (i.e. 1 row for the ENGAGEMENT)
2. The report in the resultset is the last report, in terms of the Report date
3. The count of reports matches the count of reports for that engagement,
regradless of anything else.