sql子查询返回一个以上的值
问题描述:
这里是在sql中减去两列的值,然后将结果压入另一列.我在条件下使用子查询进行减法,并报错:子查询返回两个以上的值.
请帮我查询.
here in sql am subtracting the values of a two column and dispalying the resultant in another column. i am using subquery for subtraction under a condition and am getting error: sub query returns more than two values.
please help me with query .
Select Distinct spare_list.code, spare_list.Name,indentitems.qty "Quantity", (Select IFNULL(sum(QtyAvailable), 0) from SparesQty where SparesQty.Code = spare_list.Number) as 'On Hand', ABS((Select IFNULL(sum(QtyAvailable), 0) from SparesQty where SparesQty.Code = spare_list.Number)-(select indentitems.qty from indentitems left join indent on indentitems.code=indent.itemcode where indentitems.indent=16 and indent.status=1)) as "Quantity Required"from (spare_list left join SparesQty on SparesQty.Code = spare_list.Number) Left join (indentitems left join indent on indentitems.code=indent.itemcode) on spare_list.code = indentitems.code where indentitems.indent=16 and indent.status=1 Group by spare_list.Code order by spare_list.Code
答
子查询必须返回单个值,否则会出错.
将代码放在这里.
Subquery must return a single value otherwise you will get error.
put your code here.
只需尝试逐个运行子查询,并检查哪个返回的值不止一个,以及原因.条件一定存在错误或重复数据:
Just try to run your sub queries one by one individually and check which one is returning more than one value and why.there must be something wrong in the condition or duplicate data:
((Select IFNULL(sum(QtyAvailable), 0) from SparesQty where SparesQty.Code = spare_list.Number)
(select indentitems.qty from indentitems left join indent on indentitems.code=indent.itemcode where indentitems.indent=16 and indent.status=1))