TIMEDIFF question?

MySQL

Can someone help me with a TIMEDIFF question?

Assume there’s online test with 50 questions. Write a query to return a list of test takers whose total time taken to answer all questions in 30 minutes or more. Only add the time if the time between start_date and submission_date is less than than 5 minutes for each question.

For example: if a student took more than 5 minutes to answer a question, that time doesn’t count towards the total. If a student took exactly 2 minutes to answer each question, then their total time would be 100 minutes.

Table:

Exam

——————

Field | Type |

——————

Student | VARCHAR |

Date_started | DATETIME |

Date_submitted | DATETIME |

——————

Assume it doesn’t matter if the student answered the question correctly or incorrectly.

My attempt:

SELECT STUDENT FROM EXAM

TIMEDIFF(MINUTES, DATE_STARTED, DATE_SUMBITTED) <= 5

GROUP BY STUDENT ASC;

Not sure where I can use sum somewhere in my query.

Posted May 4, 2022, 1:51 AM UTC · edited

211
Loading comments…