MySQL ATAN2 Function

MySQL ATAN2 function is one of the Numeric Functions, which is useful to return the arc tangent between specified two variables, i.e., x and y. Or you can say, it returns the angle between the positive x-axis and the line from the origin to the point (y, x). The basic syntax of the ATAN2 in MySQL is as shown below:

SELECT ATAN2 (Y, X)
FROM Source

-- Or you can use ATAN Function
SELECT ATAN (Y, X)
FROM Source

To demonstrate this ATAN2 Numeric function, we are going to use the below shown data

MySQL ATAN2 Function Example 1

MySQL ATAN2 Function Example 1

The MySQL ATAN2 returns the trigonometric Arc tangent between two values. The following query shows multiple ways to use the ATAN2 function.

-- MySQL ATAN2 Function Example

-- ATAN2 Example on Negative Value
SELECT ATAN2(-2.54, -152.56) AS `ATAN2 Value`;

-- ATAN2 Example on Positive Value
SELECT ATAN2(150.52, 224.68) AS `ATAN2 Value`;

-- ATAN2 Example on string value
SELECT ATAN2('10.35', '4.25') AS `ATAN2 Value`;

-- ATAN2 Example on String
SELECT ATAN2('MySQL', '14') AS `ATAN2 Value`;

As you can see, we used MySQL ATAN2 function to find the Arc Tangent values between two different values.

MySQL ATAN2 Function Example 2

MySQL ATAN2 Example 2

The MySQL ATAN2 Numeric also allows you to find the arctangent between two columns in a table. In this MySQL example, we are going to find the arctangent value between the standard cost column and the sales column. Here, we are also using the ATAN function to demonstrate that both these functions return the same output.

-- MySQL ATAN2, ATAN Example
USE mysqltutorial;
SELECT Product, Color,
		StandardCost, Sales, TaxAmt,
        ATAN2(StandardCost, Sales) AS `Sales ATAN2 Value`,
        ATAN(StandardCost, Sales) AS `Sales ATAN2 Value`
FROM `numeric functions`;
MySQL ATAN2 Function Example 3