Guest User

Untitled

a guest
Apr 25th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. SELECT o.id_orden, o.fecha_cancelacion, o.id_punto_suministro
  2. FROM orden o
  3. INNER JOIN
  4. punto_suministro p ON o.id_punto_suministro = p.id_punto_suministro AND p.deleted=0
  5. INNER JOIN
  6. r_contrato_punto_suministro rc ON rc.id_punto_suministro = p.id_punto_suministro AND rc.deleted=0
  7. INNER JOIN
  8. contrato c ON c.id_contrato = rc.id_contrato AND c.deleted = 0
  9. INNER JOIN
  10. r_contrato_servicio rcs on rcs.id_contrato = c.id_contrato AND rcs.deleted =0
  11. INNER JOIN
  12. servicio s on s.id_servicio = rcs.id_servicio AND s.deleted = 0
  13. INNER JOIN
  14. tipo_servicio ts on ts.id_tipo_servicio = s.id_tipo_servicio AND ts.deleted = 0
  15. WHERE p.impago = 0
  16. AND ts.id_tipo_servicio = 2
  17. AND o.status = 'OrdenWorkflow/cancelada'
  18. AND o.motivo_cancelacion = 'Impago, scoring'
  19. AND o.fecha_cancelacion is not null
  20. AND o.id_tipo = 2
  21. AND o.deleted=0
  22. AND o.fecha_cancelacion = (
  23. select fecha_cancelacion
  24. from orden t2
  25. where o.id_orden = t2.id_orden
  26. AND fecha_cancelacion >= date_add(current_date(),INTERVAL -2 MONTH)
  27. group by id_punto_suministro
  28. ORDER BY fecha_cancelacion ASC);
Add Comment
Please, Sign In to add comment