Home » SIN Function in SQL

SIN Function in SQL

by Online Tutorials Library

SIN Function in SQL

The SIN is a SQL function of mathematics which returns the sine value of the specified number.

Syntax of SIN Function

In the SIN syntax, we have to pass that decimal number whose sine value we want to return.

In the Structured Query Language, we can also use the SIN 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 SIN function.

Examples of SIN function

Example 1: This example returns the sine value of the number in the given query:

Output:

Sin_Value_of_101
0.45202578717835057

Example 2: This example returns the sine value of 2 from the following SELECT query:

Output:

Sin_Value_of_2
100.90929742682568171

Example 3: This example returns the sine value of 8:

Output:

Sin_Value_of_8
0.98935824662338179

Example 4: This example returns the Sin_Value of 255:

Output:

Sin_Value_of_255
-0.50639163492449091

Example 5: This example returns the Sin_Value of NULL:

Output:

Sin_Value_of_NULL
–

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

Output:

21 22 23 24 25 26 27 28 29 30
0.8366 -8.8513 -0.846 -0.9055 -0.1323 0.7625 0.9563 0.2709 0.6636 -0.988

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

In this example, we will create the new table through which we will perform the SIN 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:

Product_ID Product_Name Product_Quantity Purchasing_Price Selling_Price Release_Date Product_Rating
104 P1 10.250 945 NULL 2022-04-30 NULL
202 P4 15.500 45 75 2022-01-28 5
103 P2 18.250 25 NULL 2022-02-18 4
111 P7 25.250 5 15 2021-12-25 9
210 P6 15.500 50 70 2021-10-15 NULL
212 P8 19.750 110 250 2022-01-28 4
112 P10 10.250 550 835 2022-04-11 NULL

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

This query returns the sine value of each product id from the table.

Output:

Product_ID Sin_Value_of_Product_ID
104 -0.3216
202 0.80641
103 0.622
111 -0.8654
210 0.4677185
212 -0.99834
112 -0.8899956

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

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

Output:

Purchasing_Price Sin_Value_of_PurchasingPrice Selling_Price Sin_Value_of_SellingPrice
945 0.58053 NULL
45 0.85090 75 -0.387781
25 -0.132351 NULL
5 -0.9589 15 -0.650287
50 -0.262374 70 -0.773890
110 -4.42426 250 -0.97052
550 -0.21948 835 -0.61599

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

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

Output:

Product_Rating Sin_Value_of_productrating
NULL
5 -0.9589
4 -0.7568024
9 0.41211
NULL
4 -0.7568024
NULL

You may also like