SQL exercises
October 28, 03:12 MSK


forgot password?

Personal page
Developers & Thanks
For employers
Support SQL-EX.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.

Exercises under SQL Server is now checking on 2019 version.
The nearest birthdays. Do not forget to congratulate!
Alexander Tolokonnikov (Alexander_ttl) - 28, October
Aleksei Kostomarov (al29) - 29, October
Viktor Evlampiev (rhus) - 29, October
Andrey Merezhnikov (Scorpion) - 31, October
Ekaterina Gorynova (Danisa) - 1, November
Sergey Senkevich (GreyC) - 1, November
Andrey Tatarenko (=marinos=) - 1, November
Evgeniy Belov (optimizm) - 1, November
Evgeny Vaskov (Johan) - 2, November
Iryna Kuziankova (_irina_) - 2, November
Alexey Nazarenko (alex618) - 2, November

Last certified:
Marat Kasumov (Marat@dag05) - 11, October
Nikita Ladanov (XAKEP_BBC) - 23, September
Dmitry Lakalov (Meilleur_NG) - 15, September
Sergei Rodionov (oldos) - 19, August
Ramil Baynazarov (Байназаров) - 18, August
Vitaly Kovelman (jjokker) - 15, August
Данил Харицкий (Rognak) - 28, July
Alena Natynchyk (Verbena) - 15, July
Andrei Komarov (Шведа Сауля) - 13, July
Olga Akimova (vvvvvloi) - 10, July

In total: 871

Let's learn SQL

POWER and SQRT functions


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;


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.


select SQL_VARIANT_PROPERTY(3.1,'BASETYPE') basetype;


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


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 2017 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:

Week news
Copyright SQL-EX © 2002-2020. All rights reserved.