loading..
Русский    English
06:16

Exercise #53 (tips and solutions)

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

Console
Execute
  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  Cистема управления реляционными базами данных (СУБД), разработанная корпорацией Microsoft. 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
Tags
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 CONVERT correlated subqueries COUNT CROSS APPLY CTE data type conversion data types database schema date/time functions DATEADD DATEDIFF DATENAME DATEPART DATETIME DDL DEFAULT DEFAULT VALUES DELETE DISTINCT DML duplicates EXCEPT exercise (-2) exercise 19 exercise 23 exercise 32 More tags
The book was updated
month ago
©SQL-EX,2008 [Evolution] [Feedback] [About] [Links] [Team]
All right reserved.
Rambler's Top100