SQL MS ACCESS 使用列乘法创建别名
SQL MS ACCESS Create an Alias using Multiplication of Columns
您好,我无法通过将两个列值相乘来在我的 SQL 代码中创建新列 "Alias"。
问题:
- Compose a query to show every product that has a value of 0 or more. The value of each product is defined as the quantity on hand
multiplied by the unit price of that product. In the result table,
show product ID, unit price, quantity on hand, and the product value.
Sort the results by the product value in descending order.
我的代码:
Select Product_ID, Unit_Price, On_Hand, **Unit_Price * On_Hand as Product_Value**
From Product_T
Where Product_Value >= 400.00
Group by Product_ID
Order by (Product_Value) desc
我不断收到一条错误消息:
"Your Query does not include the specified expression 'unit price' as part of an aggregate function"
知道如何通过这个立交桥吗?
我认为不需要聚合。如果不是,则需要在where
中重复表达式(或使用子查询):
Select Product_ID, Unit_Price, On_Hand,
(Unit_Price * On_Hand) as Product_Value
From Product_T
Where (Unit_Price * On_Hand) >= 400.00
Order by (Unit_Price * On_Hand) desc;
如果需要聚合,则需要 having
子句:
Select Product_ID,
sum(Unit_Price * On_Hand) as Product_Value
From Product_T
Group by Product_ID
Having sum(Unit_Price * On_Hand) >= 400.00
Order by sum(Unit_Price * On_Hand) desc;
您好,我无法通过将两个列值相乘来在我的 SQL 代码中创建新列 "Alias"。
问题:
- Compose a query to show every product that has a value of 0 or more. The value of each product is defined as the quantity on hand multiplied by the unit price of that product. In the result table, show product ID, unit price, quantity on hand, and the product value. Sort the results by the product value in descending order.
我的代码:
Select Product_ID, Unit_Price, On_Hand, **Unit_Price * On_Hand as Product_Value**
From Product_T
Where Product_Value >= 400.00
Group by Product_ID
Order by (Product_Value) desc
我不断收到一条错误消息:
"Your Query does not include the specified expression 'unit price' as part of an aggregate function"
知道如何通过这个立交桥吗?
我认为不需要聚合。如果不是,则需要在where
中重复表达式(或使用子查询):
Select Product_ID, Unit_Price, On_Hand,
(Unit_Price * On_Hand) as Product_Value
From Product_T
Where (Unit_Price * On_Hand) >= 400.00
Order by (Unit_Price * On_Hand) desc;
如果需要聚合,则需要 having
子句:
Select Product_ID,
sum(Unit_Price * On_Hand) as Product_Value
From Product_T
Group by Product_ID
Having sum(Unit_Price * On_Hand) >= 400.00
Order by sum(Unit_Price * On_Hand) desc;