as400的sql中sum??
本帖最后由 jxfnew 于 2010-03-08 20:17 编辑
pf文件:
cstzlga的定義為:
Seq Field File Type Length Scale
LAPN CSTZLGA CHARACTER-O 15
LACPN CSTZLGA CHARACTER-O 15
LAQTY CSTZLGA DECIMAL 15 7
LAUDAT CSTZLGA DECIMAL 8
cstzlgb的定義:
Seq Field File Type Length Scale
LBCPN CSTZLGB CHARACTER-O 15
LBCOST CSTZLGB DECIMAL 15 7
LBLCST CSTZLGB DECIMAL 15 7
LBUDAT CSTZLGB DECIMAL 8
在as400上strsql:
用select LAQTY *
(SELECT LBCOST FROM Y2CHAUSF/CSTZLGB c WHERE LBCPN = A.lacpn AND
c.LBUDAT = (SELECT MAX( LBUDAT ) FROM Y2CHAUSF/CSTZLGB d WHERE
c.LBCPN = d.LBCPN AND LBUDAT <= 20081209)) as amt
from y2chausf/cstzlga a where lapn = 'QFE0014X000X004'
and laudat =
(SELECT max( LAUDAT ) FROM Y2CHAUSF/CSTZLGa b WHERE a.LAPN = b.lapn
and LAUDAT <= 20081209 )
能正确取出所行资料并且均有非空的数值.
select sum(round( LAQTY *
(SELECT LBCOST FROM Y2CHAUSF/CSTZLGB c WHERE LBCPN = A.lacpn AND
c.LBUDAT = (SELECT MAX( LBUDAT ) FROM Y2CHAUSF/CSTZLGB d WHERE
c.LBCPN = d.LBCPN AND LBUDAT <= 20081209)) ,7)) as amt
from y2chausf/cstzlga a where lapn = 'QFE0014X000X004'
and laudat =
(SELECT max( LAUDAT ) FROM Y2CHAUSF/CSTZLGa b WHERE a.LAPN = b.lapn
and LAUDAT <= 20081209 )
結果為:
AMT
2.84710870000000
而去掉round後
select sum( LAQTY *
(SELECT LBCOST FROM Y2CHAUSF/CSTZLGB c WHERE LBCPN = A.lacpn AND
c.LBUDAT = (SELECT MAX( LBUDAT ) FROM Y2CHAUSF/CSTZLGB d WHERE
c.LBCPN = d.LBCPN AND LBUDAT <= 20081209))) as amt
from y2chausf/cstzlga a where lapn = 'QFE0014X000X004'
and laudat =
(SELECT max( LAUDAT ) FROM Y2CHAUSF/CSTZLGa b WHERE a.LAPN = b.lapn
and LAUDAT <= 20081209 )
的結果變為空值:
AMT
-
为何会这样??
多谢!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论