Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A bus company stores each trip of one morning in a table Fares. Fare is in dollars.
TripID Route Fare
F1 Red 4
F2 Blue 6
F3 Red 5
F4 Green 3
F5 Blue 7COUNT(*) counts the records that pass the WHERE condition. SUM(Field) adds up a numeric field of the records that pass. Each gives one value. "How many orders?" is a count; "how many cups?" is a sum of the Cups field.
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. All the trips. SELECT SUM(Fare) FROM Fares; adds dollars.
Step 2. The Blue route. F2 and F5.
SELECT SUM(Fare)
FROM Fares
WHERE Route = 'Blue';The output:
SUM(Fare)
13Check. dollars.
Answer: (a) dollars. (b) dollars.
Log in to join the discussion.
Loading…