select pjid,sum(pzf)
from alltotal a
where not exists(select 1 from alltotal where pjid=a.pjid and bzf=a.bzf and riqi<a.riqi)
group by pjid
from alltotal a
where not exists(select 1 from alltotal where pjid=a.pjid and bzf=a.bzf and riqi<a.riqi)
group by pjid
select distinct pjid,bzf,riqi,sum(bzf) from 表
select sum(pzf)
from alltotal a
where not exists(select 1 from alltotal where pjid=a.pjid and bzf=a.bzf and riqi<a.riqi)
select pjid,sum(bzf) from 表 group by pjid
只能在where后过滤掉重复的pjidto xluzhong(Ralph)
你的方法提供了思路,但是仍然是错误的
to xluzhong(Ralph)
应该是:riqi<>a.riqi
select sum(bzf)
from alltotal a
where not exists(select 1 from alltotal where pjid=a.pjid and bzf=a.bzf and riqi<>a.riqi)
THANKS!
揭贴
如果是这样,sql语句这么写:select
sum(A.bzf) as TOTAL
from
( select bzf from alltotal group by pjid,bzf ) A