nee, da fehlt einfach was!

With aaa as ( ...... )

select * from aaa where ..... <---- das fehlt doch!

und im oberen teil mit sum( ...) fehlt evtl ein group by ... oder zumindest ein where