sin
sin() is a numeric function that returns the trigonometric sine value of a specified angle in radians.
Syntax
The syntax of the sin() function is:
SIN (x)
The sin() function requires one argument:
x: A positive or a negative angle (or an expression that evaluates to an angle).
Examples
Sine a positive value
This example uses the sin() function with a positive angle as the argument.
SELECT SIN(5);
This returns the sine value of 5.
+-----------------------+
| f |
+-----------------------+
| -0.9589242746631385 |
+-----------------------+
Sine a negative value
This example shows the sin() function with a negative angle as the argument:
SELECT SIN(-3);
The query returns:
+----------------------+
| f |
+----------------------+
| -0.1411200080598672 |
+----------------------+
Sine a fraction value
This example shows the sin() function with a fractional value as the argument:
SELECT SIN(5.8732);
The query returns:
+----------------------+
| f |
+----------------------+
| -0.3985959081271079 |
+----------------------+
Sine with an expression
The sin() function can also include an expression:
SELECT sin(8.5 * 2.3);
The query returns:
+-----------------------+
| f |
+-----------------------+
| 0.6445566903363104 |
+-----------------------+
Use the sin() function with a table
This example combines the sin() function with a CREATE TABLE statement to obtain the sine values of a specific column:
-
Create a new table named sineTable containing the initialValue column. Input some values with the negative and positive angles into the column.
CREATE TABLE sineTable(initialValue int); INSERT INTO sineTable(initialValue) VALUES (-5),(18), (0),(-27); -
Run this query to get the sine value output:
SELECT * ,SIN(initialValue) AS sinValue FROM sineTable; -
The final result will have the initialValue column with the source value and the sinValue column with their calculated sine values.
+---------------+-------------------------------+ | initialvalue | sinvalue | +---------------+-------------------------------+ | -5 | 0.9589242746631385 | | 18 | -0.7509872467716762 | | 0 | 0 | | -27 | -0.956375928404503 | +---------------+-------------------------------+