我创建查询以将我的商品存入我的数据库,如下所示
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
子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。
导致此错误,因为在某些商品中有两个Color
,我想为此商品获取两行
答案 0 :(得分:0)
请检查此查询
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;