Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A school garden club records each plot in a table Plots: the water it needs each day in litres, its hours of sun and whether it is shaded by a tree.
Plot WaterL SunHours Shaded
A 4 6 FALSE
B 9 3 TRUE
C 12 2 TRUE
D 2 8 FALSE
E 7 5 TRUE
F 3 7 FALSESELECT SUM(WaterL) FROM Plots WHERE Shaded = TRUE AND SunHours < 4;SELECT COUNT(*) FROM Plots WHERE WaterL > 3 OR Shaded = TRUE;With AND a record passes only if both conditions are true; with OR it passes if at least one is true. A range is Field >= low AND Field <= high; outside a range is Field < low OR Field > high. Each part needs its own field name.
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. Part (a), shaded plots. B, C and E.
Step 2. Of those, fewer than hours of sun. B () and C (). E has hours, so it fails.
Step 3. Add the water. , so the output is .
Step 4. Part (b). More than litres: A, B, C and E. Shaded: B, C and E, which are already in the list. So plots pass.
Watch out. Adding the two groups, , counts B, C and E twice. With OR each record counts once.
Answer: (a) . (b) .
Log in to join the discussion.
Loading…