我有一张表库存
StockID ItemID Quantity Price
现在我想选择一些像这样的数据
StockID ItemID Quantity Price TotalPrice(Quantity*Price)
我试过这个
ALTER PROC [dbo].[SelectItemStock]
@Item int
as
BEGIN
SELECT Stock.*, (SELECT Quantity*Price FROM Stock) AS TotalPrice
FROM Stock
WHERE ItemID = @Item
END
但它给了我错误Subquery returned more than 1 value.
请帮我解决这个问题
答案 0 :(得分:7)
您不需要执行子查询来获取两列的乘积,只需将其直接乘以,
ALTER PROC [dbo].[SelectItemStock]
@Item int
as
BEGIN
SELECT Stock.*,
(Quantity*Price) AS TotalPrice
FROM Stock
WHERE ItemID = @Item
END