SQL Server子查询返回了多个值。当子查询遵循=,!=,<,<=,>,> =时,不允许这样做我运行以下查询: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_masterWHERE invoiceid = '339740' AND orderdetails.mfr_id = supplier.supplierid AND group_master.sku = orderdetails.sku 我收到以下错误:消息512,级别16,状态1,行2子查询返回的值超过1。当子查询跟随=,!=,<,<=,>,> =或子查询用作表达式时,不允许这样做。有任何想法吗?
3 回答
qq_笑_17
TA贡献1818条经验 获得超7个赞
试试这个:
SELECT od.Sku, od.mf_item_number, od.Qty, od.Price, s.SupplierId, s.SupplierName, s.DropShipFees, si.Price as costFROM 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.SupplierIDWHERE od.invoiceid = '339740'
除了cost
列之外,这将返回多个相同的行。查看返回的不同成本值,并找出导致不同值的原因。然后向某人询问他们想要的成本值,并将标准添加到将选择该成本的查询中。
添加回答
举报
0/150
提交
取消