Guest User

Untitled

a guest
Apr 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. object_id: int
  2. param_id: int
  3. date: date
  4. value: real
  5.  
  6. param1_value as of two days ago > param2_value as of week low
  7. and sustained within past week
  8.  
  9. select opvl_exist.object_id from obj_param_value_log opvl_exist
  10. where (select count(distinct opvl_sust1.date) from obj_param_value_log opvl_sust1 /*count dates from inner join to account for possible gaps in values for either parameter*/
  11. inner join obj_param_value_log opvl_sust2 on opvl_sust1.object_id=opvl_sust2.object_id
  12. where opvl_sust1.param_id=2 /*define param1*/
  13. and opvl_sust2.param_id=32 /*define param2*/
  14. and opvl_sust1.date>=current_date() - integer '6' /*limit lookup period for param1 to a week*/
  15. and opvl_sust2.date>=current_date() - integer '6' /*limit lookup period for param2 to a week*/
  16. and opvl_sust1.object_id=opvl_exist.object_id) =
  17. (select count(distinct opvl1.date) from obj_param_value_log opvl1 /*count dates where filter condition is true*/
  18. inner join obj_param_value_log opvl2 on opvl1.object_id=opvl2.object_id
  19. where opvl1.param_id=2 /*define param1*/
  20. and opvl2.param_id=32 /*define param2*/
  21. and opvl1.date between date current_date() - integer '2' - integer '6' and current_date() - integer '2' /*set a lookup period for param1 from a week and 2 days ago to just 2 days ago*/
  22. and opvl2.value=(select min(opvl_sq.value) from obj_param_value_log opvl_sq
  23. where opvl2.object_id=opvl_sq.object_id
  24. and opvl_sq.param_id=32
  25. and opvl_sq.date between opvl1.date - integer '4' and opvl1.date + integer '2') /*set a relative lookup period to calc the min value for param2 form 4 days before param1 date to 2 days ahead param1 date*/
  26. and opvl2.date>=current_date() - integer '6' - integer '6' /*set a lookup period for param2 from today to a week ago (min value lookup) and another week ago (condition sustained period)*/
  27. and opvl1.value>opvl2.value /*set condition param1 value > param2 value*/
  28. and opvl_exist.object_id=opvl1.object_id)
Add Comment
Please, Sign In to add comment