beowulf1416

gateway minutes per country top 3

Mar 2nd, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. select
  2. res.*,
  3. res.current_week + res.last_week_days total_minutes
  4. from
  5. (
  6. select
  7. country.title country_title,
  8. sum(case when date(report.report_date) >= '2015-02-22' and date(report.report_date) <= '2015-02-27' then report.total_minutes else 0 end) current_week,
  9. sum(case when date(report.report_date) >= '2015-02-15' and date(report.report_date) <= '2015-02-20' then report.total_minutes else 0 end) last_week_days
  10. from report_total_minutes_by_day report
  11. inner join data_gateway dg on report.gateway_id = dg.id
  12. inner join data_group_country country on dg.country_id = country.id
  13. where dg.title is not null
  14. and dg.is_deleted = 0
  15. and country.is_deleted = 0
  16. and country.title is not null
  17. and date(report.report_date) >= '2015-02-14'
  18. and date(report.report_date) <= '2015-02-27'
  19. group by country.id
  20. ) res
  21. order by total_minutes desc, country_title asc
  22. limit 3
Advertisement
Add Comment
Please, Sign In to add comment