Main page
Typical errors at solution of exercises.
Exercise 51
S. Moiseenko
Find the names of the ships having the largest amount of guns among all the ships with the
same displacement (taking into account Outcomes table).
A typical mistake admited in this task is due to finding of a maximum. Here is how
it do:
select max(numGuns) guns,displacement
from classes group by displacement
That is the maximum among CLASSES of the ships though in the task formulation
there are no words about classes, this fact is not accidently emphasized in the formulation:
" among all the ships... ".
The situation when the query will work incorrectly are the following:
There is a class without the ships in a database;
For this class a number of guns is maximal among classes of the ships with the same
displacement.
This maximum is not reached among the ships of other classes.
As a result for the given displacement, the query will return no ship though those can be in the database. Conclusion: It is necessary to search for a maximum on available
ships, as it is written in the task formulation.
Main page