Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- res.*,
- res.current_week + res.last_week_days total_minutes
- from
- (
- select
- rca.title rca_title,
- 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,
- 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,
- 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,
- 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
- from report_total_minutes_by_day report
- inner join data_gateway dg on report.gateway_id = dg.id
- inner join data_group_rca rca on dg.rca_id = rca.id
- where dg.title is not null
- and dg.is_deleted = 0
- and rca.is_deleted = 0
- and rca.title is not null
- and date(report.report_date) >= '2015-02-14'
- and date(report.report_date) <= '2015-02-27'
- group by rca.id
- ) res
- order by total_minutes desc, rca_title asc
- limit 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement