LN() function :
It is the
function in MySQL is used to calculate the natural logarithm of a specific number with base e . The number must be greater than 0, otherwise it will return NULL.
Syntax :
LN(X)
Parameter :
LN() function accepts one parameter as mentioned above in the syntax and described below as follows.
X – A number whose logarithm value with base e we want to calculate. It should be a positive number.
Returns :
It returns the natural logarithm of given number x with base e.
Example-1 :
The logarithm of the given number with base e using the LN() function.
SELECT LN(1000) AS Ln_Val ;
Output :
Example-2 :
The logarithm of 0 using LN() function.
SELECT LN(0) AS Ln_Val ;
Output :
Example-3 :
The LN function can also be used to find the logarithmic value with base e of a column data. To demonstrate create a table named Product.
CREATE TABLE Product(
Product_id INT AUTO_INCREMENT,
Product_name VARCHAR(100) NOT NULL,
Buying_price DECIMAL(13, 2) NOT NULL,
Selling_price DECIMAL(13, 2) NOT NULL,
Service_grade Decimal(6, 2) NOT NULL,
PRIMARY KEY(Product_id)
);
Inserting into the Product table :
Now inserting some data to the Product table –
INSERT INTO
Product(Product_name, Buying_price, Selling_price, Service_grade)
VALUES
('Touring Bike', 20000.00, 30050.00, 4.17 ),
('Mountain Bike', 30005.50, 40000.56, 10.00 ),
('Road Bike', 10000.20, 21000.56, -3.59 ),
('Road Bicycle', 15200.50, 18000.00, -0.50 ),
('Racing Bicycle', 30500.50, 45000.00, 3.00) ;
Reading data from table :
Showing all data in Product Table –
Select * from Product;
Output :
PRODUCT_ID | PRODUCT_NAME | BUYING_PRICE | SELLING_PRICE | SERVICE_GRADE |
---|
1 | Touring Bike | 20000.00 | 30050.00 | 4.17 |
2 | Mountain Bike | 30005.50 | 40000.56 | 10.00 |
3 | Road Bike | 10000.20 | 21000.56 | -3.59 |
4 | Road Bicycle | 15200.50 | 18000.00 | -0.50 |
5 | Racing Bicycle | 30500.50 | 45000.00 | 3.00 |
Now, we are going to find the logarithmic values with base e for all the records present in the Service_grade column.
Select Product_id, Product_name, Buying_price,
Selling_price, Service_grade,
LN(Service_grade) AS GRADELOGN
FROM Product;
Output :
PRODUCT_ID | PRODUCT_NAME | BUYING_PRICE | SELLING_PRICE | SERVICE_GRADE | GRADELOGN |
---|
1 | Touring Bike | 20000.00 | 30050.00 | 4.17 | 1.4279160358107101 |
2 | Mountain Bike | 30005.50 | 40000.56 | 10.00 | 2.302585092994046 |
3 | Road Bike | 10000.20 | 21000.56 | -3.59 | NULL |
4 | Road Bicycle | 15200.50 | 18000.00 | -0.50 | NULL |
5 | Racing Bicycle | 30500.50 | 45000.00 | 3.00 | 1.0986122886681098 |
Similar Reads
LOG() Function in MySQL
LOG() function in MySQL is used to calculate the natural logarithm of a specific number. The number must be >0 Otherwise it will return NULL. Syntax : LOG(X) Parameter : This method accepts one parameter as mentioned above and described below : X : A number whose logarithm value we want to calcul
3 min read
LEFT() Function in MySQL
The LEFT() function in MySQL is used to extract a specified number of characters from the left side of a given string. It uses its second argument to decide, how many characters it should return. Syntax: LEFT (str, len)Parameter: This function accepts two parameters as mentioned above and described
1 min read
LPAD() Function in MySQL
LPAD() function in MySQL is used to pad or add a string to the left side of the original string. Syntax : LPAD(str, len, padstr) Parameter : This function accepts three parameter as mentioned above and described below - str - The actual string which is to be padded. If the length of the original str
2 min read
LOG2() Function in MySQL
In this article, we are going to cover the LOG2() function that means it will calculate the logarithm of a specific number with base 2. Pre-requisite :LOG function LOG2() function in MySQL is used to calculate the natural logarithm of a specific number with base 2. The number must be >0 Otherwise
2 min read
LEAST() Function in MySQL
The LEAST() function in MySQL is a versatile tool that returns the smallest (minimum) value from a list of expressions. It can be used with numbers, strings, or even columns of data to find the minimum value according to their data type.In this article, We will learn about LEAST() Function in MySQL
4 min read
MONTH() function in MySQL
MySQL MONTH() function returns the month from the given date. It returns a month value between 1 and 12 or returns 0 when the month part of the date is 0. It's a useful SQL function for date manipulation and analysis, particularly when dealing with reports or queries that require month-based groupin
3 min read
LTRIM() Function in MySQL
LTRIM() : This function in MySQL is used to remove leading spaces from a string. Syntax : LTRIM(str) Parameter : It accepts one parameter as mentioned above and described below as follows. str â The string from which we want to remove leading spaces. Returns : It returns a string after truncating al
2 min read
MySQL ISNULL( ) Function
The MySQL ISNULL() function is used for checking whether an expression is NULL or not. This function returns 1 if the expression passed is NULL; otherwise, it returns 0. The ISNULL() function in MySQL accepts the expression as a parameter and returns an integer with a value of a value 0 or 1 dependi
2 min read
MOD() Function in MySQL
The MOD() function in MySQL is used to find the remainder of one number divided by another. The MOD() function returns the remainder of dividend divided by divisor. if the divisor is zero, it returns NULL. Syntax: MOD(N, M) or N % M or N MOD M Parameter : MOD() function accepts two parameter as ment
4 min read
MID() function in MySQL
MID() : This function in MySQL is used to extract a substring from a given input string. If the starting position is a positive number, then the substring of the given length will be extracted from the starting index. If negative, then the substring of the given length will be extracted from the end
2 min read