Русский    English

Exercise #53 (tips and solutions)

Here is a solution where an attempt at rounding is made.

  1. SELECT CAST(ROUND(AVG(numguns), 2) AS DECIMAL(10,2)) Avg_numGuns
  2. FROM Classes
  3. WHERE type = 'bb';

The attempt is unsuccessful, since rounding as well as further casting to DECIMAL type (which is redundant in the given context, though) is carried out for a value which is already integer. In consequence, we manage to get not more than two zeroes after decimal point.

The problem lies in the fact that AVG(numguns) is applied to an integer argument, therefore the result is cast to integer as well, fractional part being discarded rather than rounded, which is a peculiarity of  A database management system (DBMS) by Microsoft Corporation. SQL(Structured Query Language) is a database computer language designed for the retrieval and management of data in relational database management systems (RDBMS), database schema creation and modification, and database object access control management.SQL Server rather than the general rule.

To return to discussion of exercise #53

To solve a problem on SQL-EX.RU

Bookmark and Share
aggregate functions Airport ALL AND AS keyword ASCII AVG Battles Bezhaev Bismarck C.J.Date calculated columns Cartesian product CASE cast CHAR CHARINDEX Chebykin check constraint classes COALESCE common table expressions comparison predicates Computer firm CONSTRAINT CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema DATEADD DATEDIFF DATENAME DATEPART DATETIME date_time functions DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates edge equi-join EXCEPT exercise (-2) More tags
The book was updated
month ago
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.