SQL 服务器- Select 进入另一个 Select 出错
SQL Server- Select Into another Select Got Error
我创建查询以在我的数据库中获取我的商品,如下所示
SELECT
Goods.GoodsID ,Max(Price)
ExistNumber AS ExistNumber ,
(SELECT p.ValueText
FROM STR.GoodsProperties gp
INNER JOIN PRP.Properties p ON p.PropertyID = gp.PropertyID
WHERE NodeText LIKE '/40/%'
AND gp.GoodsID = Goods.GoodsID) AS Color
FROM
STR.Goods
GROUP BY
Goods.GoodsID, ExistNumber;
本次查询得到的商品有他们existnumber
有颜色属性的商品,
现在当我 运行 这个查询时我得到这个错误:
Msg 512, Level 16, State 1, Line 13
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
这个错误是因为在某些商品中有两个 Color
而我想为这个商品得到两行
请检查此查询
SELECT Goods.GoodsID ,
ExistNumber AS ExistNumber ,
Prop.ValueText AS Color
FROM STR.Goods
INNER JOIN ( SELECT gp.GoodsID ,
p.ValueText
FROM STR.GoodsProperties gp
INNER JOIN PRP.Properties p ON p.PropertyID = gp.PropertyID
WHERE NodeText LIKE '/40/%'
) Prop ON Prop.GoodsID = Goods.GoodsID
GROUP BY Goods.GoodsID ,
ExistNumber ,
Prop.ValueText;
我创建查询以在我的数据库中获取我的商品,如下所示
SELECT
Goods.GoodsID ,Max(Price)
ExistNumber AS ExistNumber ,
(SELECT p.ValueText
FROM STR.GoodsProperties gp
INNER JOIN PRP.Properties p ON p.PropertyID = gp.PropertyID
WHERE NodeText LIKE '/40/%'
AND gp.GoodsID = Goods.GoodsID) AS Color
FROM
STR.Goods
GROUP BY
Goods.GoodsID, ExistNumber;
本次查询得到的商品有他们existnumber
有颜色属性的商品,
现在当我 运行 这个查询时我得到这个错误:
Msg 512, Level 16, State 1, Line 13
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
这个错误是因为在某些商品中有两个 Color
而我想为这个商品得到两行
请检查此查询
SELECT Goods.GoodsID ,
ExistNumber AS ExistNumber ,
Prop.ValueText AS Color
FROM STR.Goods
INNER JOIN ( SELECT gp.GoodsID ,
p.ValueText
FROM STR.GoodsProperties gp
INNER JOIN PRP.Properties p ON p.PropertyID = gp.PropertyID
WHERE NodeText LIKE '/40/%'
) Prop ON Prop.GoodsID = Goods.GoodsID
GROUP BY Goods.GoodsID ,
ExistNumber ,
Prop.ValueText;