MySQL LOG2 Function

MySQL LOG2 function is one of the Mathematical functions used to return the logarithmic value of a given number with base 2. Let us see how to find base 2 logarithmic values using Command Prompt and Workbench with examples.

The basic syntax of the MySQL LOG2 function is as shown below:


MySQL LOG2 Function Example

The LOG2 Function returns the logarithmic value with base 2 of any numeric integer. The following query shows multiple ways to use this one.


SELECT LOG2(623250);

SELECT LOG2(250), LOG2(-150);
LOG2 Example 1

This Mathematical method also allows you to find the base 2 logarithmic value of a column of data. In this MySQL example, we are going to find the base 2 logarithmic values for all the records present in the Standard Cost, Sales Amount, and Tax Amount columns.

SELECT EnglishProductName, 
       LOG2( StandardCost) AS LogStdCost,
       LOG2( SalesAmount) AS LogSalesAmount,
       LOG2( TaxAmt) AS TaxAmt
  FROM `mathemetical functions`;
MySQL LOG2 Function 2

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.