一个sql语句

来源:百度知道 编辑:UC知道 时间:2024/06/05 18:02:53
String sDisp= "select gno,OutL.sum(amount),IntoL.sum(amount) from IntoL,OutL where IntoL.gno = OutL.gno group by gno";

在OutL和IntoL表中都定义了amount,
提示错误是该特定字段‘gno’,可以参考SQL语句from子句列表中多个表
请问这一句哪里错了?
~~~谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢~~~
先谢谢回答~~^_^
可是我注明gno后 String sDisp= "select IntoL.gno,OutL.sum(amount),IntoL.sum(amount) from IntoL,OutL where IntoL.gno = OutL.gno group by gno";
提示错误是该特定字段‘amount’,可以参考SQL语句from子句列表中多个表
可是我的amount也给注明了,还是报错

select IntoL.gno,sum(OutL.amount),sum(IntoL.amount) from IntoL,OutL where IntoL.gno = OutL.gno group by IntoL.gno
顺便说下这种写法如果IntoL和OutL中gno相同记录有多个时,得出的sum是错误的值,如IntoL中 有 No1 100 与No1 200 两条记录,OutL也有No1 150 No1 120两条记录,这样这个格式的语句执行后会得出 No1 600 540这样的结果,而不是你想要的No1 300 270

你要指定gno是多表中的具体表名,是IntoL还是OutL。

select OutL.gno,OutL.sum(amount),IntoL.sum(amount) from
(
select * from IntoL inner join OutL on IntoL.gno = OutL.gno
)
group by OutL.gno