Monthly Revenue by Affiliate heading select from_unixtime(A.date_orig,'%Y%m') as yearmonth, from_unixtime(A.date_orig,'%M, %Y') as dates, A.sku, B.account_id from %%AGILE_DB_PREFIX%%invoice_item A inner JOIN %%AGILE_DB_PREFIX%%invoice B ON (A.invoice_id=B.id and billing_status=1 and (refund_status=0 or refund_status is null) and B.site_id=%%DEFAULT_SITE%%) A.site_id = %%DEFAULT_SITE%% AND (B.affiliate_id > 0 OR B.affiliate_id IS NOT NULL) GROUP BY yearmonth ORDER BY yearmonth DESC 0 yearmonth true true false false false Breakdown for Month: dates true select CONCAT(C.first_name,' ', C.last_name,' ', C.company) as affiliate_name, B.id as aid, count(A.id) as quan, sum(A.total_amt) as amt, from_unixtime(A.date_orig,'%Y%m') as yearmonth, B.account_id from %%AGILE_DB_PREFIX%%invoice A JOIN %%AGILE_DB_PREFIX%%affiliate B ON (A.affiliate_id=B.id and B.site_id=%%DEFAULT_SITE%%) JOIN %%AGILE_DB_PREFIX%%account C ON (B.account_id=C.id and C.site_id=%%DEFAULT_SITE%%) A.site_id = %%DEFAULT_SITE%% AND (A.affiliate_id > 0 OR A.affiliate_id IS NOT NULL) and A.billing_status=1 and (A.refund_status=0 or A.refund_status is null) GROUP BY aid ORDER BY amt DESC 30 yearmonth false false Affiliate ID aid Affiliate Name affiliate_name Invoice Quantity quan true num,0 num,0 Invoice Amount amt dol,2 true dol,2