Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.14 KB | None | 0 0
  1. -- within 1 month
  2. select count(*) from (select rl1.* from phy_req_list rl1 left join phy_req_list rl2
  3.     on (rl1.doc_type = rl2.doc_type and rl1.id = rl2.id and rl1.updated_date < rl2.updated_date)
  4. where rl2.updated_date is null) as rl_filtered_latest_udpated_date_per_id_doc_type
  5. where doc_type = 'PRC_ID' and validity_date > CURDATE() and validity_date <= DATE_ADD(CURDATE(), INTERVAL 1 MONTH);
  6.  
  7. -- within 3 months
  8. select count(*) from (select rl1.* from phy_req_list rl1 left join phy_req_list rl2
  9.     on (rl1.doc_type = rl2.doc_type and rl1.id = rl2.id and rl1.updated_date < rl2.updated_date)
  10. where rl2.updated_date is null) as rl_filtered_latest_udpated_date_per_id_doc_type
  11. where doc_type = 'PRC_ID' and validity_date > DATE_ADD(CURDATE(), INTERVAL 1 MONTH) and validity_date <= DATE_ADD(CURDATE(), INTERVAL 3 MONTH);
  12.  
  13. -- expired
  14. select count(*) from (select rl1.* from phy_req_list rl1 left join phy_req_list rl2
  15.     on (rl1.doc_type = rl2.doc_type and rl1.id = rl2.id and rl1.updated_date < rl2.updated_date)
  16. where rl2.updated_date is null) as rl_filtered_latest_udpated_date_per_id_doc_type
  17. where doc_type = 'PRC_ID' and validity_date <= CURDATE();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement