SQL exercises
Language 
December 13, 10:07 MSK
Login:

Password:

forgot password?
Registration

Personal page
Developers & Thanks
For employers
References
Feedback
Support SQL-EX.RU







Сколько стоит адвокат по уголовным делам
Адвокат по уголовным делам. Профессиональная помощь. Звоните
zabolotnyy.ru

SQL Exercises news letters, latest issue

§
As the important news can appear and between releases of news letters, I shall use this page for the publication of the information on all changes on the site.
The forum is not so suitable for this purpose since the message there "escapes" and can appear on previous page before it will lose a urgency.
So look in here if you wish to be well informed about last events on the site. The link to this page is in section of news at the main page below a subscription banner.
§

§
The nearest birthdays. Do not forget to congratulate!
ANDREY CHERANYEV (cher) - 13, December
Alexander Zaikin (Allex) - 14, December
Pavel Dmitriev (Bot) - 15, December
Alexandr Bystrov (Wind84) - 15, December
Georgy Bychkovsky (GeBy) - 16, December
Oleg Kudryashov (Olaf) - 16, December
Dmitry Ogarok (Ogarok_Dmitry) - 17, December
Nataliya Vasyaeva (V_Natali) - 17, December
Nikolay Korshunov (iNtegro) - 19, December
Valentin Nikotin (@Nikotin) - 20, December
Eugene Zrumov (Зрюмов) - 20, December

§
Last certified:
Semen Gulyaev (somak.mail.88) - 29, November
Andrey Kalinichenko (knerok) - 19, November
Dmytro Chernov (Kursist) - 11, October
Stanislav Mihalenkov (black_horse) - 20, September
Aleksandr Savin (mirovingin) - 8, September
Anatoliy Bezgubenko (oWart) - 3, September
Dmitry Yurin (Diman9425) - 31, August
Igor Shkaredny (Gosha) - 10, August
Andrey Nesterkin (nestam) - 5, August
Andrey Smirnov (vvorkandrey) - 1, August

Let's learn SQL

POWER and SQRT functions

S.I.Moiseenko

The SQL Server POWER (x, y) function raises x to the power of y.
x is an expression of type FLOAT or of a type that can be implicitly converted to FLOAT.
y is an expression of a numeric type.

The returned result has the same type as x.

The returned result is of FLOAT type.

SQRT is the inverse function of POWER(x, 2), so that SQRT(POWER(x,2)) should return x.

Let’s check this

select 3 x, power(3,2) y, sqrt(power(3,2)) sqrt_y;

x	y	sqrt_y
3	9	3

This is correct. However,

select 3.1 x, power(3.1,2) y, sqrt(power(3.1,2)) sqrt_y;

yields

x	y	sqrt_y
3.1	9.6	3,09838667696593

This unexpected result in most likelihood has to do with a loss of precision when the POWER function result type (which matches the type of the argument, NUMERIC) is implicitly converted to FLOAT.

Indeed,

select SQL_VARIANT_PROPERTY(3.1,'BASETYPE') basetype;

basetype
numeric

When we apply an equivalent conversion to retain the NUMERIC type for the result

select 3.1 x, power(3.1,2) y, power(power(3.1,2),0.5) sqrt_y;

everything works as expected.

x	y	sqrt_y
3.1	9.6	3.1

Read more...

Useful links

§ Official communities of the site sql-ex in social networks: SQL Exercises at VK.com and SQL Exercises at LinkedIn.com

§     The resource is positioned as a "handbook" for this site SQL-EX.COM, but can be used irrespective of it also.

§ The following DBMS are used on the site for solving exercises: SQL Server 2012 Express, Oracle Database 11g Express Edition, MariaDB-10.2.13 (compatible with MySQL 8), PostgreSQL 10.3.

§ If you like this site, vote for us:
del.icio.us
dzone.com
Digg.com
stumbleupon.com



Home
Week news
Certification
SQL exercises
Forums
Ratings
HELP
Performance
Profile
References
Rambler's Top100
Copyright SQL-EX © 2002-2018. All rights reserved.
contact