Exp Function In Sql in SQL
? EXP() Function in SQL
The EXP() function in SQL returns Euler’s number (e) raised to the power of a given number.
Mathematically:
\text{EXP}(x) = e^x
]
where e ? 2.71828
? Syntax:
EXP(number)number: The exponent to raise e to.
? Example:
SELECT EXP(1); -- Returns approximately 2.71828SELECT EXP(2); -- Returns approximately 7.38906SELECT EXP(0); -- Returns 1SELECT EXP(-1); -- Returns approximately 0.36788? Use Case:
Mathematical modeling
Exponential growth/decay calculations
Logarithmic conversions (along with
LOG()function)
? Example with Table:
Assume a sales_growth table:
| year | rate |
|---|---|
| 1 | 0.05 |
| 2 | 0.10 |
| 3 | 0.15 |
SELECT year, rate, EXP(rate) AS growth_multiplierFROM sales_growth;Let me know if you’d like to combine EXP() with LOG(), or use it in a real-world formula (like compound interest).