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:

21222324252627282930
-0.654112.973062966-0.4648-7.48910.8483-0.3054-3.55321.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_IDProduct_NameProduct_QuantityPurchasing_PriceSelling_PriceRelease_DateProduct_Rating
64P110.250945NULL2022-04-30NULL
88P415.50045752022-01-285
95P218.25025NULL2022-02-184
58P725.2505152021-12-259
26P615.50050702021-10-15NULL
85P819.7501102502022-01-284
91P1010.2505508352022-04-11NULL

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_IDcot_value_of_Product_ID
640.4259
8828.2322
951.06865
580.120035
260.84835
855.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:

Purchasing_Pricecot_value_of_PurchasingPriceSelling_Pricecot_value_of_SellingPrice
945-1.40255NULL-
450.6173675-2.3769
25-7.4891NULL-
5-0.2958115-1.168233
50-3.67781700.81835
11022.5804250-0.24830
5504.44504835-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_Ratingcot_value_of_productrating
NULL-
5-0.29581
40.8636911
9-2.21804
NULL-
40.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_Quantitycot_value_of_productquantity
10.2500.92336
15.500-4.73901
18.250-1.46308
25.2508.48902
15.500-4.73901
19.7500.792827
10.2500.92336





Latest Courses