SQL EXP函数
EXP是数学中的SQL函数,它返回给定数字的e的幂次。
EXP函数的语法
SELECT EXP(Number) AS Alias_Name;
在EXP语法中,我们需要传递一个十进制数,其e指数的值我们希望返回。
在结构化查询语言中,我们还可以使用EXP函数与表的字段一起使用,如下所示:
SELECT EXP(column_Name) AS Alias_Name FROM Table_Name;
在这个语法中,我们必须定义我们想要执行EXP函数的表的名称和列。
EXP函数的示例
示例1: 这个示例返回指定数字的e的幂:
SELECT EXP(2) AS e_power_of_2;
输出:
e_power_of_360
---
7.389056
示例2: 此示例返回指定数字的e的幂:
SELECT EXP(180) AS e_power_of_180;
输出:
e_power_of_180
---
1.589e+78
示例 3: 该示例返回e的90次幂:
SELECT EXP(90) AS e_power_of_90;
输出结果:
e_power_of_90
---
1.22e+39
示例4: 这个示例返回e的-45次幂:
SELECT EXP(-45) AS e_power_of_-45;
输出:
e_power_of_-45
---
0
示例 5: 这个示例返回给定表达式的e的幂:
SELECT EXP(180 / 3) AS e_power_of_Expression;
输出:
e_power_of_Expression
---
1.142e+26
示例 6: 此示例使用EXP函数与SQL表格。
在此示例中,我们将通过表格执行EXP函数来创建新表格:
以下是在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列与EXP函数:
SELECT Vehicle_ID, EXP(Vehicle_ID) AS e raised to the power_of_Vehicle_ID FROM Vehicle_Details;
这个查询显示每个车辆的车辆id的e的幂。
输出:
Vehicle_ID | e raised to the power_of_Vehicle_ID |
---|---|
140 | 6.327e+60 |
190 | 3.28e+82 |
145 | 9.39e+62 |
90 | 1.22e+39 |
45 | 34934270792009135368 |
210 | 1.59e+91 |
185 | 2.21e+80 |
查询 2: 以下 SELECT 查询使用了上述 “Vehicle_Details” 表的 “Purchasing_Vehicles” 列的 EXP 函数:
SELECT Purchasing_Vehicles, EXP(Purchasing_Vehicles) AS e raised to the power_of_PurchasingVehicles FROM Vehicle_Details;
这个查询展示了购买车辆后所产生的e的指数。
输出:
Purchasing_Vehicles | e raised to the power_of_PurchasingVehicles |
---|---|
45 | 34934270792009135368 |
180 | 1.489e+78 |
270 | 1.81e+117 |
360 | 2.218e+156 |
45 | 34934270792009135368 |
160 | 3.069e+69 |
450 | 2.707e+195 |
查询 3: 下面的 SELECT 查询使用了上面 Vehicle_Details 表的 Vehicle_Rating 列的 EXP 函数:
SELECT EXP(Vehicle_Rating) AS e raised to the power_of_vehiclerating FROM Vehicle_Details;
这个查询显示了上表中每个车辆评级的指数形式的e。
输出:
Vehicle_Rating | e raised to the power_of_vehiclerating |
---|---|
80 | 5.54e+34 |
90.85 | 2.855e+39 |
80 | 5.54e+34 |
180 | 1.489e+78 |
80 | 5.54e+4 |
95 | 1.811e+41 |
80 | 5.54e+34 |
Query 4: 以下SELECT查询使用了上述Vehicle_Details表中的Purchasing_Vehicles和Selling_Vehicles列的EXP函数:
SELECT Selling_Vehicles, EXP(Selling_Vehicles) AS e raised to the power_of_SellingVehicles FROM Vehicle_Details;
这个查询显示了每辆车销售车辆的e的幂次方。
输出:
Selling_Vehicles | e raised to the power_of_SellingVehicles |
---|---|
80 | 5.54e+34 |
180 | 1.489e+78 |
290 | 8.818e+125 |
80 | 5.54e+34 |
-15 | 0 |
-60 | 0 |
470 | 1.313e+204 |