MySQL COS Function

MySQL COS function is one of the Numeric Functions which calculates the trigonometry cosine of the specified expression. The mathematical formula for this Cosine function is COS(x) = Length of the Adjacent Side / Length of the Hypotenuse. The basic syntax of the MySQL COS function is as shown below:

SELECT COS (Numeric_Expression)
FROM Source

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

numeric Table 1

MySQL COS Function Example

The COS returns the trigonometric cosine value of any numeric value, and the following query shows multiple ways to use this one.

-- Cosine of Negative Value
SELECT COS(-10.57) AS `Cosine Value`;

-- Cosine of Positive Value
SELECT COS(7.96) AS `Cosine Value`;

-- Cosine of Numeric Expression
SELECT COS(1.75 + 2.25 - 4.00) AS `Cosine Value`;

-- Cosine of string value
SELECT COS('3.14') AS `Cosine Value`;

-- Cosine of String
SELECT COS('MySQL') AS `Cosine Value`;

From the screenshot below, you can observe that we used the COS function to find the Cosine values of different values. Here, we assigned a new name to the MySQL result as ‘Cosine Value’ using the ALIAS Column.

COS Example 2

This Numeric method also allows you to find the cosine values for the data in table columns. In this example, we are going to find the cosine for all the records present in the Tax Amount column and Service Grade column.

-- Cosine Function Example

SELECT Product, Color,
		StandardCost, Sales, TaxAmt,
        COS(TaxAmt) AS `Tax Cosine Value`,
        ServiceGrade,
        COS(ServiceGrade) AS `Grade Cosine Value`
FROM `numeric functions`;
MySQL COS Function Example 3