HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /A restaurant stores its staff in a table Staff…
HardComputer ScienceHigh School (9–10)Computer Science › Databases and SQLNumericalConceptualIGCSE

A restaurant stores its staff in a table Staff…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

A restaurant stores its staff in a table Staff. Hours is the hours worked this week.

table
StaffID  Name  Role    Hours
S1       Kai   Cook    30
S2       Lea   Waiter  18
S3       Moe   Cook    12
S4       Nia   Cook    25
S5       Oz    Waiter  35

A script should output the name and hours of every cook who worked more than 202020 hours, most hours first. It has errors.

sql
SELECT Name Hours
FROM Staffs
WHERE Role = Cook AND > 20
ORDER BY DESC Hours;

Find and correct every error, then give the output of the correct script.

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

To give the output of a script, work in this order: the table (FROM), the records that pass (WHERE), COUNT or SUM if there is one, the sort (ORDER BY), and last the selected fields (SELECT). To correct a script, check the clause order, the commas, the names, the quotes and each condition.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Step 1. The errors.

  1. No comma between the fields: Name, Hours.
  2. The table is Staff, not Staffs.
  3. Cook is text: 'Cook'.
  4. The second condition needs its field: AND Hours > 20.
  5. DESC comes after the field: ORDER BY Hours DESC.

Step 2. The correct script and its output.

sql
SELECT Name, Hours
FROM Staff
WHERE Role = 'Cook' AND Hours > 20
ORDER BY Hours DESC;

The output:

table
Name  Hours
Kai   30
Nia   25

Answer: 555 errors; the output has 222 rows, Kai 303030 and then Nia 252525.

Log in to save this for later
← All Problems
← A town library stores its readers in a table Readers…A street lamp is controlled by a light sensor L through a NOT gate… →
More onComputer Science › Databases and SQL

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Reading, completing and correcting SQL scriptsSQL: SUM, COUNT, AND, OR and Reading Query Output

More on this topic

  1. A town library stores its readers in a table Readers…Medium
  2. A gym stores its members in a table Gym…Easy
  3. A school garden club records each plot in a table Plots: the water it needs each day in litres, its…Hard
A school weather station stores one record a day in a table Weather: the rainfall in millimetres…Medium
  • A camera club lends out equipment and stores each loan in a table Loans…Medium
  • All problems on this topic →