Created
September 10, 2014 03:23
-
-
Save sclinede/351416cf4c9e90ce71bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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