我运行以下查询。
SELECT
orderdetails.sku,
orderdetails.mf_item_number,
orderdetails.qty,
orderdetails.price,
supplier.supplierid,
supplier.suppliername,
supplier.dropshipfees,
cost = (SELECT supplier_item.price
FROM supplier_item,
orderdetails,
supplier
WHERE supplier_item.sku = orderdetails.sku
AND supplier_item.supplierid = supplier.supplierid)
FROM orderdetails,
supplier,
group_master
WHERE invoiceid = '339740'
AND orderdetails.mfr_id = supplier.supplierid
AND group_master.sku = orderdetails.sku
我得到以下错误。
Msg 512, Level 16, State 1, Line 2
子查询返回1个以上的值。当子查询跟随=, !=, <, <= , >, >=或者子查询作为表达式使用时,这是不允许的。
有什么想法吗?
试试这个。
SELECT od.Sku, od.mf_item_number, od.Qty, od.Price, s.SupplierId, s.SupplierName, s.DropShipFees, si.Price as cost OrderDetails od INNER JOIN Supplier s on s.SupplierId = od.Mfr_ID INNER JOIN Group_Master gm on gm.Sku = od.Sku INNER JOIN Supplier_Item si on si.SKU = od.Sku and si.SupplierId = s.SupplierID WHERE od.invoiceid = '339740'
这将返回多条除
列外相同的行。看一下返回的不同成本值,并找出导致不同成本值的原因。然后问别人他们想要哪个成本值,并在查询中添加选择该成本的标准。cost