Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT o.id_orden, o.fecha_cancelacion, o.id_punto_suministro
- FROM orden o
- INNER JOIN
- punto_suministro p ON o.id_punto_suministro = p.id_punto_suministro AND p.deleted=0
- INNER JOIN
- r_contrato_punto_suministro rc ON rc.id_punto_suministro = p.id_punto_suministro AND rc.deleted=0
- INNER JOIN
- contrato c ON c.id_contrato = rc.id_contrato AND c.deleted = 0
- INNER JOIN
- r_contrato_servicio rcs on rcs.id_contrato = c.id_contrato AND rcs.deleted =0
- INNER JOIN
- servicio s on s.id_servicio = rcs.id_servicio AND s.deleted = 0
- INNER JOIN
- tipo_servicio ts on ts.id_tipo_servicio = s.id_tipo_servicio AND ts.deleted = 0
- WHERE p.impago = 0
- AND ts.id_tipo_servicio = 2
- AND o.status = 'OrdenWorkflow/cancelada'
- AND o.motivo_cancelacion = 'Impago, scoring'
- AND o.fecha_cancelacion is not null
- AND o.id_tipo = 2
- AND o.deleted=0
- AND o.fecha_cancelacion = (
- select fecha_cancelacion
- from orden t2
- where o.id_orden = t2.id_orden
- AND fecha_cancelacion >= date_add(current_date(),INTERVAL -2 MONTH)
- group by id_punto_suministro
- ORDER BY fecha_cancelacion ASC);
Add Comment
Please, Sign In to add comment