Learn with Abdou

Reading · Lesson 17

Review the first-midterm skills

Part 1 of 2

Write, predict and explain

First answer on paper without running the query. Then use the browser to test your prediction and explain any revision.

Review SELECT and WHERE, aggregates, functions, grouping, and ER modeling. The Canvas guide is the authority for allowed exam materials and scope.

Worked example
SELECT category, COUNT(*) AS items FROM menu_items WHERE price >= 5 GROUP BY category HAVING COUNT(*) >= 2 ORDER BY category;

WHERE price >= 5 changes the input population first. GROUP BY collects those expensive items into categories, and HAVING keeps only categories with at least two remaining items.

Moving the count condition into WHERE is not equivalent. Removing WHERE is valid SQL but changes both the category counts and the business question.

Pause and explain. Why would WHERE price >= 3 answer a different question?

Part 2 of 2

Explain a design decision

A shop can exist before it hires an employee. Every employee belongs to exactly one shop. Work from the requirements, rather than inventing a rule from a small sample.

Worked example
A shop has zero or many employees. An employee belongs to exactly one shop. employees.shop_id is a NOT NULL foreign key to shops(id).
Pause and explain. Explain your choice aloud without looking at the worked answer.