COS Function in SQLThe COS is a SQL function of mathematics which returns the cosine value of the specified number. Syntax of COS FunctionIn the COS syntax, we have to pass that decimal number whose cosine value we want to return. In the Structured Query Language, we can also use the COS function with the field of the table as shown in the following block: In this syntax, we have to define the name and column of that table on which we want to perform the COS function. Examples of COS functionExample 1: This example returns the cosine value of the number in the given query: Output:
Example 2: This example returns the cosine value of 2 from the following SELECT query: Output:
Example 3: This example returns the cosine value of 8: Output:
Example 4: This example returns the Cos_Value of 255: Output:
Example 5: This example returns the Cos_Value of 90: Output:
Example 6: This example returns the Cos_Value of NULL: Output:
Example 7: This example returns the cosine value of all the numbers between 21 and 30: Output:
Example 8: This example uses the COS function with the SQL table. In this example, we will create the new table through which we will perform the COS function on numerical columns: 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:
Query 1: The following SELECT query uses the COS function with the Product_Quantity column of the above Product_Details table: This query returns the cosine value of each product id from the table. Output:
Query 2: The following SELECT query uses the COS function with the and Purchasing_Price and Selling_Price column of the above Product_Details table: This query shows the cosine value of purchasing and selling price of each product. Output:
Next TopicCOT Function in SQL
|