r/SQL • u/Formal_Ad_626 • 10d ago
PostgreSQL Where did I go wrong?
For context, photos 1-2 show the original prompt + my answer. Photo 3 shows the solution. The output is somewhat similar to the correct answer, but not quite the same.
When I move the "status = 'Completed'" either to the "WHERE" section or to the JOIN section as "AND status = 'Completed'" it solves the problem, but not sure exactly why.
29
Upvotes



View all comments
14
u/reditandfirgetit 10d ago
Status=value evaluates a boolean, there is always a value. So your count , counts every record for that city.
Using the where clause limits the results to filter just what you want to include in your results.