|
查看: 2519|回复: 4
|
SQL:Subquery return more than 1 value
[复制链接]
|
|
|
小弟是VB新手, 目前stuck在一个问题几天了,希望各位大大能帮小弟看一看
下面是 Report table
| Item | subitem | inqty | outqty | yield | | ItemA | SIA | 123 | 100 | | | ItemA | SIB | 321 | 280 | | | ItemA | SIC | 123 | 80 | |
小弟想要算出出产率(yield) ,下面是我的code:
update report set yield = (select cast(outqty as real)/cast(inqty as real) from report a inner join report b on a.subitem = b.subitem)
结果就出现了下面的 error message:
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated."
小弟google后发现这样的问题可以用select max 来解决,可是小弟的情况如果用max, yield就只有最高的数据,而不是subitem各自的数据。 小弟已经stuck几天了, 希望各位大大能指导一下小弟该如何写这个code. 先谢谢了! |
|
|
|
|
|
|
|
|
|
|
发表于 24-7-2010 12:01 AM
|
显示全部楼层
为什么你report inner join 回 report?? 两个不同table? 一个table的话这样就可以了
update report set yield = cast(outqty as real)/cast(inqty as real) |
|
|
|
|
|
|
|
|
|
|
发表于 24-7-2010 12:02 AM
|
显示全部楼层
回复 1# 小阿松
为什么你report inner join 回 report?? 两个不同table? 一个table的话这样就可以了
update report set yield = cast(outqty as real)/cast(inqty as real) |
|
|
|
|
|
|
|
|
|
|
发表于 24-7-2010 01:43 AM
|
显示全部楼层
select Item, SubItem, InQty, OutQty, OutQty / InQty AS Yield
FROM report
Scalar value 通常不需要放进 db吧 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 24-7-2010 09:06 PM
|
显示全部楼层
谢谢楼上两位的回复, 之前就是因为stock住所以script也越写越不懂自己在写什么了 >"<
因为是report module所以要show一些statistic的东西给user. |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|