Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- sum(if(t2.tip_sdelki = "pr" and t1.status in ("processing","closing"), t3.summ, null)) `pg_summ_pr`,
- sum(if((t1.type="service" or (t1.type="buy_n_sale" and t2.tip_sdelki = "ar")) and t1.status in ("processing","closing"), t3.summ, null)) `pg_summ_ar`,
- sum(if(t2.tip_sdelki = "pr" and t1.status="success", t3.summ, null)) `fc_summ_pr`,
- sum(if((t1.type="service" or (t1.type="buy_n_sale" and t2.tip_sdelki = "ar")) and t1.status="success", t3.summ, null)) `fc_summ_ar`
- from
- crm_deal_list t1
- join crm_klt_obr t2 on (t1.type="service" and t2.id=t1.buy_obr_id) or
- (t1.type="buy_n_sale" and t1.sell_from="crm_obr" and t2.id=t1.sell_obr_obj_id) or
- (t1.type="buy_n_sale" and t1.sell_from="1rs_obj" and t2.id=t1.buy_obr_id)
- join crm_deal_agents t3 on t3.deal_id=t1.id
- join crm_MAIN_users t4 on t4.id=t3.agent_id
- where t1.status in ("processing", "closing", "success") and t1.deal_date between '2020-01-01 00:00:00' and '2020-01-21 23:59:59'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement