その他の数学関数

中級 SQL Server

Ginger Grant

Instructor

絶対値

ABS() を使用して非負の値を返します

ABS(number)
中級 SQL Server

T-SQLでのABSの使用(I)

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

中級 SQL Server

T-SQLでのABSの使用(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

T-SQLでの平方と平方根

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

中級 SQL Server

対数

  • LOG() は自然対数を返します
  • 底を指定することもできます。省略した場合は 2.718281828 になります

 

LOG(number [,Base])
中級 SQL Server

T-SQLでの対数計算

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

0の対数

0の対数はエラーになるため計算できません

SELECT LOG(0, 10)

An invalid floating point operation occurred.
中級 SQL Server

では、練習しましょう!

中級 SQL Server

Preparing Video For Download...