SQL ASIN函数
ASIN是SQL中的数学函数,它返回指定数字的反正弦值。如果指定的数字不在-1到1之间,则此函数返回NULL值。
ASIN函数的语法
SELECT ASIN(Number) AS Alias_Name;
在ASIN语法中,我们必须传递想要计算其反正弦值的数字。
在结构化查询语言中,我们也可以使用ASIN函数与表的列一起使用,如以下代码块所示:
 SELECT ASIN(column_Name) AS Alias_Name FROM Table_Name;
在此语法中,我们必须定义要执行ASIN函数的表的名称和列。
ASIN函数示例
示例1: 此示例返回指定数字的ASIN值:
 SELECT ASIN(0.5) AS ASIN_Value_of_0.5;
输出:
ASIN_Value_of_0.5   
---  
0.523598   
示例2: 此示例返回指定数字的反正弦值:
 SELECT ASIN(0.9) AS ASIN_Value_of_0.9;
输出:
ASIN_Value_of_0.9   
---  
1.1197   
示例 3: 此示例返回0.1的ASIN值:
 SELECT ASIN(0.1) AS ASIN_Value_of_0.1;
输出:
ASIN_Value_of_0.1   
---  
0.10016   
示例 4: 在这个示例中,我们将使用ASIN函数和SQL表。
在这个示例中,我们将通过这个新表执行ASIN函数来创建新表:
以下是在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语句创建了一个用于存储产品价格和数量的 Product_Details 表:
CREATE TABLE Product_Details
(
Product_ID INT NOT NULL,
Product_Name Varchar(50),
Product_Quantity INT,
Purchasing_Price INT,
Selling_Price INT,
Release_Date Date, 
Product_Rating INT
);
以下是多个INSERT查询,将产品和其售价、购买价记录插入到Product_Details表中:
INSERT INTO Product_Details (Product_ID, Product_Name, Product_ Quantity Purchasing_Price, Selling_Price, Release_Date, Product_Rating) VALUES (0.1, P1, 0.250, 0.5, NULL, 2022-04-30, NULL);
INSERT INTO Product_Details (Product_ID, Product_Name, Product_ Quantity Purchasing_Price, Selling_Price, Release_Date, Product_Rating) VALUES (0.2, P4, 5.500, 0.45, -0.8, 2022-01-28, 0.25);
INSERT INTO Product_Details (Product_ID, Product_Name, Product_ Quantity Purchasing_Price, Selling_Price, Release_Date, Product_Rating) VALUES (0.3, P2, 0.350, 0.85, 0.250, 2022-02-18, 0.15);
INSERT INTO Product_Details (Product_ID, Product_Name, Product_ Quantity Purchasing_Price, Selling_Price, Release_Date, Product_Rating) VALUES (0.4, P7, 0.850, 0.355, NULL, 2021-12-25, 0.45);
INSERT INTO Product_Details (Product_ID, Product_Name, Product_ Quantity Purchasing_Price, Selling_Price, Release_Date, Product_Rating) VALUES (0.5, P6, 0.900, 0.5, -0.500, 2021-10-15, NULL);
INSERT INTO Product_Details (Product_ID, Product_Name, Product_ Quantity Purchasing_Price, Selling_Price, Release_Date, Product_Rating) VALUES (0.6, P8, 0.750, 0.110, -0.95, 2022-01-28, -0.9);
INSERT INTO Product_Details (Product_ID, Product_Name, Product_ Quantity Purchasing_Price, Selling_Price, Release_Date, Product_Rating) VALUES (0.7, P10, 0.250, 0.550, 0.258, 2022-04-11, NULL);
以下 SELECT 语句显示了上述 Product_Details 表的插入记录:
SELECT * FROM Product_Details; 
| Product_ID | Product_Name | Product_Quantity | Purchasing_Price | Selling_Price | Release_Date | Product_Rating | 
|---|---|---|---|---|---|---|
| 0.1 | P1 | 0.250 | 0.5 | NULL | 2022-04-30 | NULL | 
| 0.2 | P4 | 0.500 | 0.45 | -0.8 | 2022-01-28 | 0.25 | 
| 0.3 | P2 | 0.350 | 0.85 | 0.250 | 2022-02-18 | 0.15 | 
| 0.4 | P7 | 0.850 | 0.355 | NULL | 2021-12-25 | 0.45 | 
| 0.5 | P6 | 0.900 | 0.5 | -0.500 | 2021-10-15 | NULL | 
| 0.6 | P8 | 0.750 | 0.110 | -0.95 | 2022-01-28 | -0.9 | 
| 0.7 | P10 | 0.250 | 0.550 | 0.258 | 2022-04-11 | NULL | 
查询1: 以下SELECT查询使用了上面Product_Details表的Product_Quantity列的ASIN函数:
SELECT Product_ID, ASIN(Product_ID) AS ASIN_Value_of_Product_ID FROM Product_Details;
该查询显示每个产品的产品ID的反正弦值。
输出:
| Product_ID | ASIN_Value_of_Product_ID | 
|---|---|
| 0.1 | 0.10016 | 
| 0.2 | 0.2013579 | 
| 0.3 | 0.30469 | 
| 0.4 | 0.411516 | 
| 0.5 | 0.523598 | 
| 0.6 | 0.6435011 | 
| 0.7 | 0.775397 | 
查询2: 下面的SELECT查询使用了上述Product_Details表的ASIN函数和Purchasing_Price和Selling_Price列:
SELECT Purchasing_Price, ASIN(Purchasing_Price) AS ASIN_Value_of_PurchasingPrice, Selling_Price, ASIN(Selling_Price) AS ASIN_Value_of_SellingPrice FROM Product_Details;
这个查询展示了上表中每个产品的购买和销售价格的反正弦值。
输出:
| Purchasing_Price | ASIN_Value_of_PurchasingPrice | Selling_Price | ASIN_Value_of_SellingPrice | 
|---|---|---|---|
| 0.5 | 0.523598 | NULL | - | 
| 0.45 | 0.46676 | -0.8 | -0.9272952 | 
| 0.85 | 1.01598 | 0.250 | 0.25268 | 
| 0.355 | 0.362914 | NULL | - | 
| 0.5 | 0.523598 | -0.500 | 0.523598 | 
| 0.110 | 0.11022 | -0.95 | -1.25323 | 
| 0.550 | 0.582364 | 0.258 | 0.2609515 | 
查询3: 下面的SELECT查询使用上面Product_Details表的Product_Rating列的ASIN函数:
SELECT ASIN(Product_Rating) AS ASIN_Value_of_productrating FROM Product_Details;
此查询显示上表中每个产品的评分的反正弦值。
输出:
| Product_Rating | ASIN_Value_of_productrating | 
|---|---|
| NULL | - | 
| 0.25 | 0.25268 | 
| 0.15 | 0.150568 | 
| 0.45 | 0.46676533 | 
| NULL | - | 
| -0.9 | -1.1197695 | 
| NULL | - | 
 极客笔记
极客笔记