Advertisement
psi_mmobile

Untitled

Jul 9th, 2020
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. SELECT d.vehicle_id, d.last_vehicle_data_id, b.vehicle_data_id
  2. FROM
  3. (SELECT v.vehicle_id,
  4. v.last_vehicle_data_id
  5. FROM vehicle v,
  6. vo_vehicle_category vovc
  7. WHERE v.vo_vehicle_category_id = vovc.vo_vehicle_category_id
  8. AND NVL(vehicle_status_id,0) = 0
  9. AND NVL(vovc.is_active,'Y') = 'Y'
  10. AND v.last_vehicle_data_id IS NOT NULL
  11. and lower(vovc.name) not like 'old%'
  12. ) d,
  13. (SELECT vd.vehicle_data_id,
  14. vd.vehicle_id,
  15. vd.gps_full_date
  16. FROM vehicle_data vd,
  17. (SELECT v.vehicle_id,
  18. MAX(vd.gps_full_date) AS dt
  19. FROM vehicle_data vd,
  20. vehicle v
  21. WHERE vd.vehicle_id = v.vehicle_id
  22. AND NVL(v.vehicle_status_id,0) = 0
  23. GROUP BY v.vehicle_id
  24. ) d
  25. WHERE d.vehicle_id = vd.vehicle_id
  26. AND d.dt = vd.gps_full_date
  27. ) b
  28. where d.vehicle_id = b.vehicle_id
  29. and d.last_vehicle_data_id != b.vehicle_data_id;
  30.  
  31. SELECT d.person_id, d.last_person_data_id, b.person_data_id
  32. FROM
  33. (SELECT p.person_id,
  34. p.last_person_data_id
  35. FROM person p,
  36. vo_person_category vopc
  37. WHERE p.vo_person_category_id = vopc.vo_person_category_id
  38. AND NVL(person_status_id,0) = 0
  39. AND NVL(vopc.is_active,'Y') = 'Y'
  40. AND p.last_person_data_id IS NOT NULL
  41. and lower(vopc.name) not like 'old%'
  42. ) d,
  43. (SELECT pd.person_data_id,
  44. pd.person_id,
  45. pd.event_date
  46. FROM person_data pd,
  47. (SELECT p.person_id,
  48. MAX(pd.event_date) AS dt
  49. FROM person_data pd,
  50. person p
  51. WHERE pd.person_id = p.person_id
  52. AND NVL(p.person_status_id,0) = 0
  53. GROUP BY p.person_id
  54. ) d
  55. WHERE d.person_id = pd.person_id
  56. AND d.dt = pd.event_date
  57. ) b
  58. where d.person_id = b.person_id
  59. and d.last_person_data_id != b.person_data_id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement