SQL DEGREES函数
DEGREES是结构化查询语言中的数学函数,它将指定的弧度转换为角度。
这个函数接受弧度角作为参数,并返回相应的角度。函数的返回类型与参数类型相同。
DEGREES函数的语法
语法1: 这个语法使用DEGREES函数与SQL表的列名:
SELECT DEGREES(Numeric_Column_Name) AS Alias_Name FROM Table_Name;
在这个SELECT语法中,我们需要指定我们想要使用DEGREES函数的数值列的名称。
语法2: 我们也可以像下面的块中展示的那样使用DEGREES函数与特定的数字一起使用:
SELECT DEGREES(Numeric value) AS Alias_Name;
DEGREES函数示例
示例1: 此示例返回指定数字的度数值:
SELECT DEGREES(360) AS Degreevalue_of_360;
输出:
Degreevalue_of_360
---
20626.5
示例2: 此示例返回指定数字的度值:
SELECT DEGREES(180) AS Degreevalue_of_180;
输出:
Degreevalue_of_180
---
10313.2
示例 3: 该示例返回90弧度的角度值:
SELECT DEGREES(90) AS Degreevalue_of_90;
输出:
Degreevalue_of_90
---
5156.62
例子4: 这个例子返回-45弧度的度值:
SELECT DEGREES(-45) AS Degreevalue_of_-45;
输出:
Degreevalue_of_-45
---
-2578.31
示例5: 该示例返回给定表达式的Degree值:
SELECT DEGREES(180 / 3) AS Degreevalue_of_Expression;
输出:
Degreevalue_of_Expression
---
3437.75
示例6: 此示例使用SQL表中的DEGREES函数。
在此示例中,我们将通过新建表来执行DEGREES函数的列操作:
下面是在SQL中创建新表的语法示例:
CREATE TABLE Name_of_New_Table
(
First_Column_of_table Data Type (character_size of First Column),
Second_Column_of_table Data Type (character_size of the Second column ),
Third_Column_of_table Data Type (character_size of the Third column),
.......,
Last_Column_of_table Data Type (character_size of the Last column)
);
以下CREATE语句创建了 Vehicle_Details 表,用于存储购买和销售车辆的详细信息:
CREATE TABLE Vehicle_Details
(
Vehicle_ID INT NOT 80,
Vehicle_Name Varchar(50),
Vehicle_Quantity INT,
Purchasing_Vehicles INT,
Selling_Vehicles INT,
Release_Date Date,
Vehicle_Rating INT
);
以下的多个INSERT查询将车辆的记录插入Vehicle_Details表中,包括它们的数量以及销售和购买的车辆数量:
INSERT INTO Vehicle_Details (Vehicle_ID, Vehicle_Name, Vehicle_ Quantity Purchasing_Vehicles, Selling_Vehicles, Release_Date, Vehicle_Rating) VALUES (140, P1, 290, 45, 80, 2022-04-30, 80);
INSERT INTO Vehicle_Details (Vehicle_ID, Vehicle_Name, Vehicle_ Quantity Purchasing_Vehicles, Selling_Vehicles, Release_Date, Vehicle_Rating) VALUES (190, P4, 15, 180, 180, 2022-01-28, 90.85);
INSERT INTO Vehicle_Details (Vehicle_ID, Vehicle_Name, Vehicle_ Quantity Purchasing_Vehicles, Selling_Vehicles, Release_Date, Vehicle_Rating) VALUES (145, P2, 20, 270, 290, 2022-02-18, 80);
INSERT INTO Vehicle_Details (Vehicle_ID, Vehicle_Name, Vehicle_ Quantity Purchasing_Vehicles, Selling_Vehicles, Release_Date, Vehicle_Rating) VALUES (90, P7, 10, 360, 80, 2021-12-25, 180);
INSERT INTO Vehicle_Details (Vehicle_ID, Vehicle_Name, Vehicle_ Quantity Purchasing_Vehicles, Selling_Vehicles, Release_Date, Vehicle_Rating) VALUES (45, P6, 35, 45, -15, 2021-10-15, 80);
INSERT INTO Vehicle_Details (Vehicle_ID, Vehicle_Name, Vehicle_ Quantity Purchasing_Vehicles, Selling_Vehicles, Release_Date, Vehicle_Rating) VALUES (210, P8, 30, 160, -60, 2022-01-28, 95);
INSERT INTO Vehicle_Details (Vehicle_ID, Vehicle_Name, Vehicle_ Quantity Purchasing_Vehicles, Selling_Vehicles, Release_Date, Vehicle_Rating) VALUES (185, P10, 290, 450, 470, 2022-04-11, 80);
以下SELECT语句显示了上述 Vehicle_Details 表中插入的记录:
SELECT * FROM Vehicle_Details;
Vehicle_ID | Vehicle_Name | Vehicle_Quantity | Purchasing_Vehicles | Selling_Vehicles | Release_Date | Vehicle_Rating |
---|---|---|---|---|---|---|
140 | P1 | 290 | 45 | 80 | 2022-04-30 | 80 |
190 | P4 | 15 | 180 | 180 | 2022-01-28 | 90.85 |
145 | P2 | 20 | 270 | 290 | 2022-02-18 | 80 |
90 | P7 | 10 | 360 | 80 | 2021-12-25 | 180 |
45 | P6 | 35 | 45 | -15 | 2021-10-15 | 80 |
210 | P8 | 30 | 160 | -60 | 2022-01-28 | 95 |
185 | P10 | 290 | 450 | 470 | 2022-04-11 | 80 |
查询1: 下面的SELECT查询使用上述Vehicle_Details表的Vehicle_ID列的DEGREES函数:
SELECT Vehicle_ID, DEGREES(Vehicle_ID) AS Degree value_of_Vehicle_ID FROM Vehicle_Details;
这个查询显示了每个车辆的车辆 ID 的 Degree 值。
输出:
Vehicle_ID | Degree value_of_Vehicle_ID |
---|---|
140 | 8021.41 |
190 | 10886.2 |
145 | 8307.89 |
90 | 5156.62 |
45 | 2578.31 |
210 | 12032.1 |
185 | 10599.7 |
查询2: 下面的SELECT查询在上面的Vehicle_Details表中使用DEGREES函数与Purchasing_Vehicles列进行计算:
SELECT Purchasing_Vehicles, DEGREES(Purchasing_Vehicles) AS Degree value_of_PurchasingVehicles FROM Vehicle_Details;
这个查询显示了购买车辆的度值。
输出结果:
Purchasing_Vehicles | Degree value_of_PurchasingVehicles |
---|---|
45 | 2578.31 |
180 | 10313.2 |
270 | 15469.9 |
360 | 20626.5 |
45 | 2578.31 |
160 | 9167.32 |
450 | 25783.1 |
查询3: 以下SELECT查询使用了上述Vehicle_Details表的Vehicle_Rating列的DEGREES函数:
SELECT DEGREES(Vehicle_Rating) AS Degree value_of_vehiclerating FROM Vehicle_Details;
该查询显示了上表中每辆车的评级程度值。
输出:
Vehicle_Rating | Degree value_of_vehiclerating |
---|---|
80 | 4583.66 |
90.85 | 5205.321 |
80 | 4583.66 |
180 | 10313.2 |
80 | 4583.66 |
95 | 5443.1 |
80 | 4583.66 |
查询4: 以下SELECT查询使用了上述Vehicle_Details表中Purchasing_Vehicles和Selling_Vehicles列的DEGREES函数:
SELECT Selling_Vehicles, DEGREES(Selling_Vehicles) AS Degree value_of_SellingVehicles FROM Vehicle_Details;
这个查询显示了每辆车的销售车辆的Degree值。
输出:
Selling_Vehicles | Degree value_of_SellingVehicles |
---|---|
80 | 4583.66 |
180 | 10313.2 |
290 | 16615.8 |
80 | 4583.66 |
-15 | -859.437 |
-60 | -3437.75 |
470 | 26929 |