Fatal query error: with active as (select distinct a.nextdate as month from allmonth a, recurring r where a.pdate > r.created and a.nextdate <= r.expires and a.pdate > date_sub(date(now()),interval 13 month) and r.vid=), mfcc as (select a.month, count(*) as nfunds from usemfcc u,active a where a.month=last_day(u.stamp) and u.sid= group by a.month), portf as (select a.month,count(*) as nport from portlog p,active a where a.month=last_day(p.stamp) and p.sid= and p.action='costanalysis' group by a.month), monthly as (select a.month ,ifnull(m.nfunds,0) as nfunds ,ifnull(p.nport,0) as nport from active a left join mfcc m on a.month=m.month left join portf p on a.month=p.month) select count(*) as nmonth ,avg(nfunds) as avgfunds,max(nfunds) as maxfunds ,avg(nport) as avgports,max(nport) as maxports from monthly