somedeadman

Untitled

Sep 5th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. SET @date_A = '2018-09-01';
  2. SET @date_B = '2018-09-01';
  3.  
  4.  
  5. SELECT DATE(ot.in_go_np), cp.*,
  6. IFNULL(SUM(ttn.delivery_in_out), 0) AS 'sum'
  7. FROM orders_time ot
  8. LEFT JOIN order_ttn_log l ON l.order_id = ot.order_id
  9. LEFT JOIN order_ttn_contact_persons cp ON l.spd_contact_id = cp.id
  10. LEFT JOIN order_ttn ttn ON ot.order_id = ttn.order_id
  11. WHERE DATE(ot.in_go_np) BETWEEN @date_A AND @date_B
  12. AND cp.active = 1
  13. AND ttn.redelivery_type = 1
  14. AND ttn.delivery_in_out > 1
  15. GROUP BY cp.id
  16. ORDER BY sum ASC
Advertisement
Add Comment
Please, Sign In to add comment