读书人

SQL!count子查询有关问题

发布时间: 2012-03-24 14:00:46 作者: rapoo

SQL求助!count子查询问题,

SQL code
select  '合计',         sum(case when a.Pid='999' then (select count(*) from TParty tp  where a.fiID=tp.fsID)  else null end),         sum(case when a.Pid='999' then round(a.ffValue/10000.00,2) else null end)from CaseGP a 


帮忙改造一个SQL,SYBASE数据库过来的,CaseGP和TParty 是一对多的关系。
执行报:[IBM][CLI Driver][DB2/NT] SQL0112N 列函数 "SYSIBM.SUM" 的操作数包括列函数、标量全查询或子查询。 SQLSTATE=42607


问题在第一列里面,sum里面有COUNT函数,因为不拆成多个语句,一个语句完成。


[解决办法]
SQL code
select  '合计', sum(case when a.Pid='999' then b.num  else null end), sum(case when a.Pid='999' then round(a.ffValue/10000.00,2) else null end)from CaseGP a,(select count(*) as num from TParty tp,CaseGP c  where c.fiID=tp.fsID) as b 

读书人网 >IBM DB2

热点推荐