MySQL LOG2 function is one of the Mathematical Function which is used to return the logarithmic value of a given number with base 2.
In this article, we will show you, How to find base 2 logarithmic values in MySQL using Command Prompt, and Workbench with examples.
MySQL LOG2 Syntax
The basic syntax of the LOG2 in MySQL is as shown below:
SELECT LOG2(x) FROM Source
MySQL LOG2 Function Example 1
The LOG2 Function is used to return the logarithmic value with base 2 of any numeric value. The following query will show multiple ways to use LOG2 function.
SELECT LOG2(250), LOG2(-150);
MySQL LOG2 Example 2
The MySQL LOG2 Function also allows you to find the base 2 logarithmic value of a column data.
In this example, we are going to find the base 2 logarithmic values for all the records present in Standard Cost, Sales Amount and Tax Amount columns.
LOG2( StandardCost) AS LogStdCost,
LOG2( SalesAmount) AS LogSalesAmount,
LOG2( TaxAmt) AS TaxAmt
FROM `MySQL Tutorial`.`mathemetical functions`;
Thank You for Visiting Our Blog