Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A gym stores its members in a table Gym. Visits is the number of visits this month.
MemberID Member Plan Visits
G1 Ola Gold 14
G2 Raj Basic 6
G3 Sue Gold 9
G4 Tim Basic 11
G5 Uma Gold 3Give the output of this script.
SELECT Member, Visits
FROM Gym
WHERE Plan = 'Gold' AND Visits > 5
ORDER BY Visits ASC;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.
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. WHERE. Gold members: Ola (), Sue (), Uma (). More than visits: Ola and Sue.
Step 2. ORDER BY. Fewest visits first: Sue, then Ola.
Step 3. SELECT.
SELECT Member, Visits
FROM Gym
WHERE Plan = 'Gold' AND Visits > 5
ORDER BY Visits ASC;The output:
Member Visits
Sue 9
Ola 14Answer: rows: Sue, ; Ola, .
Log in to join the discussion.
Loading…