Kumaran P

Kumaran P

  • NA
  • 102
  • 10.6k

Sql code needed same table with time difference

Apr 8 2018 12:46 PM
Dear all,
 
here with attached server table in the below.
 
let take increment_id   
 
1 . if  100173953  status Pending to Processing it should not be moved more than 10 minutes   
2. if  100173953 status Processing to Out delivery it should not be moved more than 15 minutes 
3. and 100173953 status more than 120 minutes 
 
above conditions true means I need that increment_id's for the below table  
 
Someone, please help me  
 my code not working 
 
  1. SELECT f.increment_id,  
  2. ,TIMESTAMPDIFF(MINUTE,f.created_at,a.created_at) PP  
  3. ,TIMESTAMPDIFF(MINUTE,a.created_at,b.created_at) PO  
  4. ,TIMESTAMPDIFF(MINUTE,b.created_at,c.created_at) OC  
  5. FROM sales_flat_order_status_history f  
  6. INNER JOIN sales_flat_order_status_history a on a.parent_id = f.parent_id  
  7. INNER JOIN sales_flat_order_status_history b on b.parent_id = f.parent_id  
  8. INNER JOIN sales_flat_order_status_history c on c.parent_id = f.parent_id  
  9. WHERE f.status ='pending'  
  10. and a.status= 'processing'  
  11. and b.status='out_delivery'  
  12. and c.status ='complete'  
  13. and  
  14. (TIMESTAMPDIFF(MINUTE,f.created_at,CURRENT_TIMESTAMP()) >10 or  
  15. TIMESTAMPDIFF(MINUTE,a.created_at,CURRENT_TIMESTAMP()) >15 or  
  16. TIMESTAMPDIFF(MINUTE,b.created_at,CURRENT_TIMESTAMP()) >30  
  17. )and f.created_at BETWEEN NOW() - INTERVAL 60 DAY AND NOW()  
  18. GROUP BY f.increment_id  order by f.increment_id  ; 

Answers (3)