Plus de fonctions mathématiques

Intermédiaire SQL Serveur

Ginger Grant

Instructor

Valeur absolue

Utilisez ABS() pour renvoyer des valeurs non négatives

ABS(number)
Intermédiaire SQL Serveur

Utiliser ABS en T-SQL (I)

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

Intermédiaire SQL Serveur

Utiliser ABS en 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               |
+--------------------+--------------------+ 
Intermédiaire SQL Serveur

Carrés et racines carrées en T-SQL

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

Intermédiaire SQL Serveur

Logarithmes

  • LOG() renvoie le logarithme népérien
  • En option, vous pouvez définir la base ; si elle n'est pas définie, elle vaut 2.718281828

 

LOG(number [,Base])
Intermédiaire SQL Serveur

Calculer des logarithmes en T-SQL

SELECT  DurationSeconds, LOG(DurationSeconds, 10) AS LogSeconds
FROM Incidents
+--------------------+--------------------+  
|DurationSeconds     |LogSeconds          |
+--------------------+--------------------+  
|37800               |4.577491799837225   |
|5                   |0.6989700043360187  |
|20                  |1.301029995663981   |
...
+--------------------+--------------------+  
Intermédiaire SQL Serveur

Logarithme de 0

Vous ne pouvez pas calculer le log de 0 : cela génère une erreur

SELECT LOG(0, 10)

An invalid floating point operation occurred.
Intermédiaire SQL Serveur

Passons à la pratique !

Intermédiaire SQL Serveur

Preparing Video For Download...