Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- res.*,
- res.last_week + res.current_week total
- from (
- select
- dg.id,
- dg.title,
- sum(case when report.report_date >= current_date - interval 2 week and report.report_date <= current_date - interval 2 week then report.total_minutes else 0 end) last_week,
- sum(case when report.report_date >= current_date - interval 1 week and report.report_date <= current_date then report.total_minutes else 0 end) current_week
- from report_2015_1 report
- inner join data_gateway dg on report.gateway_id = dg.id
- where dg.title is not null
- and dg.is_deleted = 0
- and dg.rca_id = 1095206
- and report.report_date >= '2015-01-01'
- and report.report_date <= '2015-02-10'
- group by dg.id
- ) res
- order by res.last_week + res.current_week desc
- limit 3;
Advertisement
Add Comment
Please, Sign In to add comment