Altre funzioni matematiche

SQL Server intermedio

Ginger Grant

Instructor

Valore assoluto

Usa ABS() per ottenere valori non negativi

ABS(number)
SQL Server intermedio

Uso di ABS in T-SQL (I)

SELECT ABS(-2.77), ABS(3), ABS(-2)
+--------------------+-------------------+-------------------+
|(No column name)    |(No column name)   |(No column name)   |
+--------------------+-------------------+-------------------+
|2.77                |3                  |2                  |
+--------------------+-------------------+-------------------+

SQL Server intermedio

Uso di ABS in T-SQL (II)

SELECT DurationSeconds, ABS(DurationSeconds) AS AbsSeconds 
FROM Incidents
+--------------------+--------------------+ 
|DurationSeconds     |AbsSeconds          | 
+--------------------+--------------------+ 
|-25.36              |25.36               | 
|-258482.44          |258482.44           |
|45.66               |45.66               |
+--------------------+--------------------+ 
SQL Server intermedio

Quadrati e radici quadrate in T-SQL

SELECT SQRT(9) AS Sqrt, 
       SQUARE(9) AS Square
+--------+-----------+ 
|Sqrt    |Square     |
+--------------------+
|3       |81         |
+--------+-----------+

SQL Server intermedio

Logaritmi

  • LOG() restituisce il logaritmo naturale
  • Facoltativamente puoi impostare la base; se omessa è 2.718281828

 

LOG(number [,Base])
SQL Server intermedio

Calcolare i log in T-SQL

SELECT  DurationSeconds, LOG(DurationSeconds, 10) AS LogSeconds
FROM Incidents
+--------------------+--------------------+  
|DurationSeconds     |LogSeconds          |
+--------------------+--------------------+  
|37800               |4.577491799837225   |
|5                   |0.6989700043360187  |
|20                  |1.301029995663981   |
...
+--------------------+--------------------+  
SQL Server intermedio

Logaritmo di 0

Non puoi calcolare il logaritmo di 0: genera un errore

SELECT LOG(0, 10)

An invalid floating point operation occurred.
SQL Server intermedio

Esercitiamoci!

SQL Server intermedio

Preparing Video For Download...