sql - MySQL: JOIN sum of multiple values -


i have query calculates invoice table invoice. invoice has taxes associated located in tax_recv table. tax_recv have multiple rows tied invoice in invoice table.

i have query calculates 12 months worth of invoices , orders them corresponding date. here query:

select      invoice_amount + late_fee + sum(c.tax) amount, tollfree_json, date_generated       invoices  left join      csi_tax_recv c  on      c.invoice_number = i.id       date_format(date_generated,'%y-%m') < date_format(now(),'%y-%m')  ,      date_format(date_generated,'%y-%m') >= date_format(now() - interval 12 month,'%y-%m')  order      date_generated 

the problem query, is returning 1 row? not sure why. minute remove left join , sum(c.tax) (which think causing issue), query works great.

the end result should this:

invoice_amount + total_taxes_for_invoices,  tollfree_json, date_generated 

cheers.

as people said, need group fields want sum of taxes , make calculations sum, this:

   select         i.tollfree_json,         i.date_generated,         (i.invoice_amount + i.late_fee + sum(c.tax)) amount              invoices join csi_tax_recv c on i.id = c.invoice_number              date_format(date_generated,'%y-%m') < date_format(now(),'%y-%m')     ,         date_format(date_generated,'%y-%m') >= date_format(now() - interval 12 month,'%y-%m')      group         i.tollfree_json,         i.date_generated      order         i.date_generated 

with query, sum of taxes aggregated every tollfree_json , date_generated combination, , can add invoice_amount , late_fee sum, if looked for.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -