Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created March 1, 2017 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/bec2ad716ed4b71ca1c9fbb94138f296 to your computer and use it in GitHub Desktop.
Save anonymous/bec2ad716ed4b71ca1c9fbb94138f296 to your computer and use it in GitHub Desktop.
invoices-sipwise-sent SQL
select
ctr.id as cliid,
inv.id as invid,
date_format(period_start,'%Y%m') as inici,
date_format(period_end,'%Y%m') as fi,
round(amount_total,2) as total,
sent_date as enviat,
cnt.email as email,
concat(cnt.firstname,' ',cnt.lastname) as customer
from billing.contracts as ctr
left join billing.contacts as cnt on ctr.contact_id = cnt.id
left join billing.invoices as inv on ctr.id = inv.contract_id
where
ctr.status='active' and
ctr.external_id is not null
and inv.period_start >= '2017-01-01 00:00:00'
and inv.period_end <= '2017-02-01 00:00:00'
order by ctr.id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment