Exercise #11 (tips and solutions) |
||
Existence of standard aggregate function AVG solves all issues: However the forum shows the attempts to be distant from the general "grey" mass. Here is quite equivalent solution which, the truth, adds the extra operation in the procedural plan: Correctness of the following decision depends on available restrictions: Namely, if SUM (speed) ignores rows with NULL value of speed, expression SUM(1) will count up total of rows in PC table, which, in essence, is equivalent to use of COUNT(*). As a result the sum of speeds of all the personal computers except for rows with unknown speed will be calculated in numerator which will be divided by the total number of rows. Therefore all the presented solutions will be equivalent, if NULL values are inadmissible, i.e. there is restriction NOT NULL on a speed column . To return to discussion of exercise #11 To solve a problem on SQL-EX.RU |