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:

FROM Source

-- Or you can use ATAN Function
FROM Source

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

MySQL ATAN2 Function Example 1

MySQL ATAN2 Function Example

The MySQL ATAN2 returns the trigonometric Arc tangent between two values, and the following query shows multiple ways to use this one.

-- 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

This Numeric method 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.

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