Books and articles about SQL Rambler's Top100 Сменить язык на: Русский 20 April 2024 01:14:32


www.sql-ex.ru
Skip Navigation Links  

 

Print  Print version

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

Print  Print version


Usage of any materials of this site is possible
only under condition of mandatory allocation of the direct link to a site
http://www.sqlbooks.ru
on each page where used materials are placed.

 Main   Articles    Books 
Рейтинг@Mail.ru Rambler's Top100 Alt Упражнения по SQL: обучение, тестирование, сертификация по языку SQL Copyright c 2002-2006. All rights reserved.