Advertisement
Guest User

Untitled

a guest
Feb 27th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. select
  2. res.*,
  3. res.current_week + res.last_week_days total_minutes
  4. from
  5. (
  6. select
  7. rca.title rca_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. sum(case when date(report.report_date) >= '2015-02-15' and date(report.report_date) <= '2015-02-21' then report.total_minutes else 0 end) current_week_2,
  11. sum(case when date(report.report_date) >= '2015-02-08' and date(report.report_date) <= '2015-02-14' then report.total_minutes else 0 end) current_week_3
  12. from report_total_minutes_by_day report
  13. inner join data_gateway dg on report.gateway_id = dg.id
  14. inner join data_group_rca rca on dg.rca_id = rca.id
  15. where dg.title is not null
  16. and dg.is_deleted = 0
  17. and rca.is_deleted = 0
  18. and rca.title is not null
  19. and date(report.report_date) >= '2015-02-14'
  20. and date(report.report_date) <= '2015-02-27'
  21. group by rca.id
  22. ) res
  23. order by total_minutes desc, rca_title asc
  24. limit 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement