# COT Function in SQL

The COT is mathematics function which returns the cotangent value of the given number in the Structured Query Language.

### Syntax of COT Function

In the COT syntax, we have to pass that numeric number in the function whose cot value we want to calculate.

In the Structured Query Language, we can also use the COT function in the SELECT query with the table fields:

In this SELECT query, we have to define the name and field of that table on which we want to perform the COT function.

### Examples of COT function

Example 1: This example returns the cotangent value of the specified number:

Output:

cot_value_of_90
-0.501202

Example 2: This example returns the cotangent value of the specified number:

Output:

cot_value_of_45
0.6173696

Example 3: This example returns the cotangent value representation of 19:

Output:

cot_value_of_19
6.596764247280

Example 6: This example returns the cotangent value of all the numbers between 21 and 30:

Output:

21 22 23 24 25 26 27 28 29 30
-0.654 112.973 062966 -0.4648 -7.4891 0.8483 -0.3054 -3.5532 1.1272 -0.1561

Example 7: This example uses the COT function with the SQL table.

In this example, we will create the new table through which we will perform the COT function on the numeric fields of the table:

The following shows the syntax to create the new table in SQL:

The following CREATE statement creates the Product_Details table for storing the price and quantity of products:

The following multiple INSERT queries insert the records of products with their selling and purchasing price into the Product_Details table:

The following SELECT statement displays the inserted records of the above Product_Details table:

Product_ID Product_Name Product_Quantity Purchasing_Price Selling_Price Release_Date Product_Rating
64 P1 10.250 945 NULL 2022-04-30 NULL
88 P4 15.500 45 75 2022-01-28 5
95 P2 18.250 25 NULL 2022-02-18 4
58 P7 25.250 5 15 2021-12-25 9
26 P6 15.500 50 70 2021-10-15 NULL
85 P8 19.750 110 250 2022-01-28 4
91 P10 10.250 550 835 2022-04-11 NULL

Query 1: The following SELECT query uses the COT function with the Product_Quantity column of the above Product_Details table:

This query displays the cotangent value of each product id from the products table.

Output:

Product_ID cot_value_of_Product_ID
64 0.4259
88 28.2322
95 1.06865
58 0.120035
26 0.84835
85 5.590647
91 -9.38193

Query 2: The following SELECT query uses the COT function with the and Purchasing_Price and Selling_Price column of the above Product_Details table:

This query shows the cotangent value of purchasing and selling price of each product.

Output:

945 -1.40255 NULL -
45 0.61736 75 -2.3769
25 -7.4891 NULL -
5 -0.29581 15 -1.168233
50 -3.67781 70 0.81835
110 22.5804 250 -0.24830
550 4.44504 835 -1.27883

Query 3: The following SELECT query uses the COT function with the Product_Rating column of the above Product_Details table:

This query shows the cot value of rating of each product from the above table.

Output:

Product_Rating cot_value_of_productrating
NULL -
5 -0.29581
4 0.8636911
9 -2.21804
NULL -
4 0.8636911
NULL -

Query 4: The following SELECT query uses the COT function with the Product_Quantity column of the above Product_Details table:

This query shows the cotangent value of quantity of each product from the above table.

Output:

Product_Quantity cot_value_of_productquantity
10.250 0.92336
15.500 -4.73901
18.250 -1.46308
25.250 8.48902
15.500 -4.73901
19.750 0.792827
10.250 0.92336