
testChecks01
Task
Your professor gave the class a bonus task: Write a program that will check the answers for the latest test. The program will be given a table Answers with the following columns:
id(smallint)
– the unique ID of the question;correct_answer(varchar[1])
– the correct answer to the question, given as a string;given_answer(varchar[1])
– the answer given to the question, which can be NULL.
Your task is to return the table with a column id
and a column checks
, where for each Answers id
the following string should be returned:
"no answer"
if thegiven_answer
is empty;"correct"
if thegiven_answer
is the same as thecorrect_answer
;"incorrect"
if thegiven_answer
is not empty and is incorrect.
Order the records in the answer table by id
.
You could use IS NULL
/ IS NOT NULL
to check if the field has value or not.
Example
For given table Answers
id | correct_answer | given_answer |
1 | A | A |
2 | B | NULL |
3 | C | B |
the output should be
id | checks |
1 | correct |
2 | no answer |
3 | incorrect |
Input/ Output:
- [Execution time limit] : 2s(PostgreSQL)
- [Input] : Data of table
Answers.
- [Output] : Display the table with a column
id
and a columnchecks
.
Post Comment