Loading Now

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 the given_answer is empty;
  • "correct" if the given_answer is the same as the correct_answer;
  • "incorrect" if the given_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 column checks.

Post Comment

Contact