Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A teacher stores test results as (Student, Score): (Ama, 64), (Ben, 70), (Chloe, 88), (Dev, 69), (Ezra, 75), (Femi, 52), (Gia, 70). The table is called Results.
She wants the names of the students who scored at least . Her first try is:
SELECT Student FROM Results WHERE Score > 70;WHERE keeps only the records for which the condition is true. The operators are =, <>, >, <, >= and <=. Text goes in quotes, numbers do not, and a Boolean field is compared with TRUE or FALSE. The field in the condition need not be selected.
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. Her script. Score > 70 keeps Chloe () and Ezra (): names.
Step 2. What is wanted. At least means or more, so Ben and Gia (exactly ) belong too: Ben, Chloe, Ezra and Gia. That is names.
Step 3. The correction.
SELECT Student
FROM Results
WHERE Score >= 70;The output:
Student
Ben
Chloe
Ezra
GiaWatch out. "At least" is >=, "more than" is >. "At most" is <=, "less than" is <.
Answer: (a) . (b) . (c) SELECT Student FROM Results WHERE Score >= 70;.
Log in to join the discussion.
Loading…