Skip to content

Instantly share code, notes, and snippets.

@sclinede
Created September 10, 2014 03:23
Show Gist options
  • Save sclinede/351416cf4c9e90ce71bd to your computer and use it in GitHub Desktop.
Save sclinede/351416cf4c9e90ce71bd to your computer and use it in GitHub Desktop.
select sum(coalesce(least(valid_to::date, now()::date) - valid_from::date, 0))/30.0 as diff_sum, company_id from company_packet_history where packet_id <> 0 and company_id in (select company_id from company_billings where ind_packet <> 0) group by company_id order by company_id desc limit 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment