sql子查询返回一个以上的值 [英] sql sub query returns a more than one value

查看:167
本文介绍了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))


这篇关于sql子查询返回一个以上的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆